dimanche 23 février 2020

I would like to do a While loop using HTML and JavaScript however with my current code the loop is not ending

Currently the loop is running constantly. It seems my else function is not being read properly. Could someone please send some assistance.

Also when I run it on Google Chrome, the first thing to pop up is a "Hello Null" box meaning that the window.alert function is running automatically.

<html>
  <head>
    <title>JavaScript Example</title>
    <script>
      "use strict";
        function start() {
          let ino = window.prompt("What is your name?");
          window.alert("Hello " + ino);
          while (ino != "end") {
            let ino = window.prompt("What is your name?");
            window.alert("Hello " + ino);}
        else {window.alert("go away now mate"); }
            }

    </script>
  </head>
  <body onLoad="start()"> 
    <p>Javascript Test Page</p>
  </body>
</html>

Aucun commentaire:

Enregistrer un commentaire