Jump to content

aserif

New Members
  • Posts

    2
  • Joined

  • Last visited

aserif's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. This is the output. I'm expecting it to be the same as the console output, but it isn't. In the browser it starts from --> LoopCount: 1, and in the console it starts from --> LoopCount is now: 5. It's interesting that if we put the --> inner.HTML right after the equals sign, the output is the same in the browser as well as in the console: The code: while(loopCount > 0) { var target = document.getElementById("target"); target.innerHTML = target.innerHTML + "LoopCount: " + loopCount + "<br>"; console.log("LoopCount is now: " + loopCount); console.log(target.innerHTML); loopCount = loopCount -1; } And this is the output with the updated code: I don't know how important it is for me to understand this right now. If it isn't all that big of a deal I can just forget about it, but till now everything was super easy and clear. And by the way thanks for the awesome course. U R THE MAN Steff (If it is you actually answering these questions haha). I''ve been jumping from Coursera to Udemy to FreeCodeCamp for months before I found ur videos on Youtube and consequently bought ur webstack course. Thanks again.
  2. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Ch7 JavaScript Loops</title> <!-- Nerd term: data = information. databases = bases of data, big collections information - Type of loops in JS: while, do/while, for, for/in Nerd term: evaluate the condition! --> <script> function doItAgain() { var loopCount = 3; while(loopCount > 0) { var target = document.getElementById("target"); target.innerHTML = "LoopCount " + loopCount + ' <br> ' + target.innerHTML console.log("The loopCount is now: " + loopCount); console.log(target.innerHTML); loopCount = loopCount - 1; } } </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 = "blue"; } </script> </body> </html> Hey Stef! He got it in the middle of the night, but l'm having trouble understanding it in the middle of the day, 3rd day in a row. Here is the HTML code. I also added a line of code --> console.log(target.innerHTML); before the --> loopCount = loopCount - 1; just so it shows it in the console as well. It seems to be the same case there, but it doesn't even get rid of the previous iteration. And it prints out the <br> as well. Thanks
×
×
  • Create New...