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