Jump to content

+ target.innerHTML with loops


webmanz

Recommended Posts

3.52 minute mark of chapter 7 part 3 Loops

 

Q1: Why does the  + target.innerHTML added at the end (see code below) appear in ascending order on the web page rather than descending like it does in the console.log?

I do realize that you can achieve descending result by adding + target.innerHTML in the front to match console.log but I'm curious why when added to the end it gives a ascending order rather than descending order?

Here's the code from that lesson 3.52 minute mark of chapter 7 video part 3 Loops:

function doItAgain(message){
 var loopCount=5;

while (loopCount > 0) {
    var target = document.getElementById("target");
    target.innerHTML="LoopCount:" + loopCount + "<br> + target.innerHTML;    <------------  referring to this line

console.log("loopCount is now:" + loopCount);
loopCount=loopCount -1;
}
console.log ("End loop");
var button= document.getElementById("looper");
button.value="Done looping!";
}

 

Edited by webmanz
Link to comment
Share on other sites

  • 2 weeks later...

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...