+ 1

Is it possible to have more than one "else if" conditional statement in the same script. Even tried this code didn't work.

var x = 1 If (x == 1) { document.write("joy) } else if (x == 2) { document.write("love") } else if (x == 3) is { document.write("peace") } else { document.write ("health") }

1st Jan 2017, 9:21 PM
Idowu Shogbon
Idowu Shogbon - avatar
3 Respostas
+ 2
Yes, it's possible, you've just made a lot of syntax errors: line 2, if has a capitalized "i"; line 3, you forgot to close the string with the double quotes; line 8, unnecessary "is" word. You're also forgetting to end statements with semicolons (' ; ').
1st Jan 2017, 9:27 PM
Dao
Dao - avatar
+ 1
Hi there, Just one question. Is it not printing joy out? It won't print love, peace, or health out because you're not changing the amount of "x", but if it's not working at all, try using print("joy"); You also need a semicolon (;) at the end of your document.write. Hope it helped!
1st Jan 2017, 9:29 PM
Cherry
Cherry - avatar
+ 1
Thanks guys Did helped
2nd Jan 2017, 8:25 AM
Idowu Shogbon
Idowu Shogbon - avatar