jeudi 23 juillet 2015

How do I declare a variable inside an if else satement?

var user = prompt("what is your         name?");
if (user == "joe")  {
var game = "what's up joe"
}
if (user == "alex") {
var game = "hello alex how are you"
}
else {
game = "sorry don't know you"
}

var other = alert(game);

For some reason this does not work I want to make game be equal to a number of different things. If I use more than 3 if statements game is always equal to the last one. Could someone please help me?

Aucun commentaire:

Enregistrer un commentaire