dick doeven dick doeven - 6 months ago 54
Javascript Question

button wont submit script

I'm currently trying t make a script for educational purposes. Now I want to check the answers people give by using a little script. But I think everything is well-programmed, however it wont submit. any ideas?

Ik<input id="invulvraag1" type="text" placeholder="h..."> Marie.
<button onclick="myFunction()">Controleer</button>
<p id="demo"></p>

function myFunction() {
var text = document.getElementById("invulvraag1").value;
var text;

// Het antwoord is correct
if (text === "heet") {
text = "perfect, goedzo!";

// het antwoord is iets anders
} else {
text = "helaas.. het had "heet" moeten zijn.";
document.getElementById("demo").innerHTML = text;


For frontend programming you will need to use console (dev tools). Press F12 or right click inspect element for safari.

In console tab you will see : js error :

SyntaxError: Unexpected identifier 'heet'

Fix : This line :

 text = "helaas.. het had "heet" moeten zijn.";

must be :

text = "helaas.. het had 'heet' moeten zijn.";


 text = 'helaas.. het had "heet" moeten zijn.';