javascript - How do I declare a variable inside an if else statement? -
var user = prompt("what name?"); if (user == "joe") { var game = "what's joe" } if (user == "alex") { var game = "hello alex how you" } else { game = "sorry don't know you" } var other = alert(game);
for reason not work want make game equal number of different things. if use more 3 if statements game equal last one. please me?
declare "game" outside if statement use inside.
var user = prompt("what name?"); var game = ""; if (user == "joe") { game = "what's joe" } else if (user == "alex") { game = "hello alex how you" } else { game = "sorry don't know you" } var other = alert(game);
Comments
Post a Comment