Jump to content
Killersites Community
Sign in to follow this  
webmanz

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

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>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×