The code below runs alert('Please enter your name!'); only when the user clicks Cancel on the prompt. I am trying to make the code also run said alert if the user doesn't input anything in the prompt box and clicks Enter. However, when they input nothing and click Enter, the code renders "Hello". How do I go about that?
var theName = prompt('What is your name?');
if(theName != null) {
document.write('Hello, ' + theName);
}
else{
alert('Please enter your name!');
}