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>
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.