+ 2

If / Else Help!

So I have been modifying a javascript that I made a while ago, and currently I have been attempting to fix a part of the script by adding an "else" statement at the end of it in order to execute a certain command if the response given is not "good" or "bad". When I try to load this script, nothing happens, therefore I must be doing something wrong. Can anyone tell me why this script isn't working? Script: var name = prompt("What is your name?"); var response = prompt("Nice to meet you, " + name + ". Are you feeling good or bad today?"); if (response == "good") { document.write("You're doing well " + name + ", that's great to know! Goodbye!"); } else if (response == "bad") { document.write("I see, " + name + ". "); var scale = prompt("Aw, that's too bad! On a scale of 1 through 10, how bad do you think youre feeling?"); if (scale == "1") { document.write(" Only 1? That shouldn't be that bad!") } else if (scale == "2") { document.write(" Hey, 2 isn't the worst! Cheer up!"); } else if (scale == "3") { document.write(" Hey, at least it isn't 4!"); } else if (scale == "4") { document.write(" 4? Cheer up!"); } else if (scale == "5") { document.write(" 5? Meh."); } else if (scale == "6") { document.write(" Well, at least it isn't 7!"); } else if (scale == "7") { document.write(" Hey! 7 is my favorite number!"); } else if (scale == "8") { document.write(" 8 is less than 9, right? Cheer up!"); } else if (scale == "9") { document.write(" Hey, at least 9 isn't a double digit!"); } else if (scale == "10") { document.write(" Well arent you negative! Go find something to cheer yourself up!"); } else { document.write(" Hey, I said 1-10! My processor isn't intelligent enough for those types of numbers!"); } else { document.write("You're doing " + response + "? I'm sorry, but I don't understand that statement."); } When I added the else part at the end, the script stopped working.

3rd Apr 2017, 6:15 PM
iBrandon
iBrandon - avatar
4 Réponses
+ 7
You missed } before last else statement (line number 6 from down) Hence 7 th last line should be:- }}
3rd Apr 2017, 6:19 PM
Meharban Singh
Meharban Singh - avatar
+ 3
Thanks for the help!
3rd Apr 2017, 9:11 PM
iBrandon
iBrandon - avatar
+ 2
Also, I was wondering if in javascript there was a way to add a "goto" command, therefore if a certain response is given the script will redirect to a specific part of the document.
3rd Apr 2017, 6:17 PM
iBrandon
iBrandon - avatar
+ 1
I guess you could do something similar to goto with functions but as far as I know there is no goto command in JS.
3rd Apr 2017, 7:06 PM
Luca Garrera