jeudi 19 juillet 2018

basic if statment brain fart HTML javascript

trying to learn javascript for the first time i am stuck on an issue involving an if statement I want the user to be able to put in the text a letter then have the computer say whether what he put in was right or wrong when I run this it usually skips some part of the if statement. this could be because I'm using the != symbol but I don't know below is the code to show you what I am working with I hope I can get you some help!

 <!DOCTYPE html>
 <html>
 <head>
 <title>Page Title</title>
 </head>
 <body>
      <form>
      First name:<br>
      <input type="text" id = "text" name="firstname">
      </form> 
     <button type="button" id ="Submit">Submit!</button> 

 </body>
 <script>
 document.getElementById("Submit").onclick = function(){
 var a = "'a', 'b', 'c'";
 var enter = document.getElementById("text").value;
 a.toString();
 if (a == enter){
    alert("congrats");
     }
  else if(enter == null){
      alert("you put nothing");
   }
  else if (enter != a){
      alert("wrong try again")
   }
  else{
      alert("End of if statment")

  }

  }
  </script> 
  </html> 

Aucun commentaire:

Enregistrer un commentaire