Jump to content

For loop code didn't work like in chapter 7, lesson 4


webmanz

Recommended Posts

Can someone tell me why my code didn't produce the same results as in Chapter 7 lesson 4.

I only managed to get Loop Count: 10 to appear, I'm not able to get Loop Count: 0 to 9.

<!DOCTYPE html>
<html>
<head>

      <meta charset="UTF-8">
      
      <title> Ch7 Javscript Loops</title>
    <script>
        function doItAgain(message){

        for (var i=10; i>=0; i--) {
            var target = document.getElementById("target");
            target.innerHTML = "LoopCount:" + i + "<br>" + target.innerHTML;
            cosole.log("LoopCount is now: " + i);
        }


            console.log ("End for loop");
            var button = document.getElementById("looper");
            button.value="Done looping!";
            //button.style.fontSize="34px";
        

        }
    </script>
    
    
    </head>
<body>

    <h1>Looping can make your code spin!</h1>
    
    <input type="button" id="looper" value="Do it again!">
    <p id="target"></p>


        <script>

    document.getElementById("looper").onclick=function(){
    doItAgain();
    this.style.color="red";
    }

   </script>
   
</body>

</html>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...