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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -