Jump to content
Killersites Community
Sign in to follow this  
webmanz

+ target.innerHTML with loops

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

Share this post


Link to post
Share on other sites

Sorry for the delay. 

Has to do how console.log works in the browser. Not important to know those details ... just get your code working in the web browser. 

Stef

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  

×