+ 2
Alert not working
Hi so this code was meant to show an alert message saying please enter a name if user doesnt enter a name.But once i dont enter a name it shows the inner html.Could it be that the else statement is wrong https://code.sololearn.com/WZweJ4x3kvHj/?ref=app
4 Answers
+ 15
Glad to help. ^_^
+ 13
<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
    </head>
    <body>
    
    <h2 id="Name"> </h2>
    
    <script>
    var Yourname=prompt("what is your name");
    
    if(Yourname){
          document.getElementById("Name").innerHTML="hello  "+     Yourname;
    }
    else{
        alert("please enter a name");
    }
    </script>
    </body>
</html>
+ 13
Because when user enters nothing an empty string is returned.
Yourname != null
should be:
Yourname
+ 1
thank you



