Reputation: 49
Why doesn't this code work? My visual studio code is telling me that the "else" in "else if" has declaration or statement expected. my script:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var a = 1+1;
var y = 1.5*2
if (a = 2){
for (var i = 0; i<5; i = i + 2){
document.write("Hello "+ i +" Everyone.</br>")
} else if (y=3){
for (var j = 2; j < 10; j = j+3){
document.write("Hey there.")
}
}
}
</script>
</body>
</html>
https://i.sstatic.net/Gwc1c.png
Upvotes: 1
Views: 57
Reputation: 1099
Your code didn't work for a couple of reasons:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var a = 1+1;
var y = 1.5*2
if (a === 2) {
for (var i = 0; i<5; i = i + 2) {
document.write("Hello "+ i +" Everyone.</br>")
}
} else if (y === 3) {
for (var j = 2; j < 10; j = j+3){
document.write("Hey there.")
}
}
</script>
</body>
</html>
Upvotes: 7