Total beginner bere, could somebody explain why this if statement isnt working? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Total beginner bere, could somebody explain why this if statement isnt working?

var name = prompt("Please tell me your name?"); if (name != null) { alert("Hello " + name + "! How are you?"); } else { alert("You didn\'t enter a name!"); } How would I check if the prompt string is 'null/empty'? Thanks!

20th Jul 2017, 5:31 AM
Danj Wood
Danj Wood - avatar
2 Answers
+ 5
use " "
20th Jul 2017, 5:43 AM
Art456
Art456 - avatar
+ 1
var name = prompt("Please tell me your name?"); if (name != "") { alert("Hello " + name + "! How are you?"); } else { alert("You didn\'t enter a name!"); } /*Use this*/
20th Jul 2017, 6:03 AM
LordGhostX
LordGhostX - avatar