ipodlover3354 ipodlover3354 - 3 months ago 7
HTML Question

What is wrong with this JavaScript in my html file?

I made this HTML file:

<html>
<body>
<head>
<title>Don't Starve Drawings</title>
<link href='style.css' rel='stylesheet'>
<center>
<p>
<script>
function updateScript();{
var wilson = document.getElementById("wilson");
var willow = document.getElementById("willow");
var mighty = document.getElementById("mighty");
}
window.addEventListener("click",function(event){

updateScript();
console.log(wilson+willow+mighty);
});
</script>
<h1>
<strong>
Welcome!
</strong>
</h1>
<h4>
<strong>Website is still in Beta</strong>
</h4>
</p>
<p>
<input style="text" name="wilson" id="wilson" maxlength="1" size="1">Wilson Drawing
</p>
<p>
<input style="text" name="willow" id="willow" maxlength="1" size="1">Willow Drawing
</p>
<p>
<input style="text" name="mighty" id="mighty" maxlength="1" size="1">Mighty Drawing
</p>
</center>
</head>
</body>
</div>
</html>


My problem is that the JavaScript console always prints:

Uncaught SyntaxError: Unexpected token ;

I know only basic JavaScript so I have no idea why this code is wrong. D:

What is the problem within my code???

Answer

Uncaught SyntaxError: Unexpected token ; means that you've put an extra semicolon somewhere you shouldn't have.

In this case, you have an extra semicolon after your function declaration. Instead of

 function updateScript();{
            var wilson = document.getElementById("wilson");
            var willow = document.getElementById("willow");
            var mighty = document.getElementById("mighty");
            }

You should use

 function updateScript() {
            var wilson = document.getElementById("wilson");
            var willow = document.getElementById("willow");
            var mighty = document.getElementById("mighty");
            }