8. When to "while" and when to "for"


what am I supposed to do. I have no clue what I did wrong.


You have to do both a for loop and a while loop

while(condition) {
// Do while condition is true

for(start; end; increment) {
// Do something!


-That you are using the semicolon ";" in your for loop.
-That your while loop has got a variable declared outside the loop. "var variable = true;"
-The for loop doesn't need an already declared variable, so as an example here.

var variable = true;

while(variable) {
console.log("Hey there!");
variable = false;

for(i = 1; i > 5; i++) {


this might be confusing as you won't see a result from it because the condition is already false in the first loop.


count = true;

for (var i = 0; i < 3; i++){
console.log("for looping");
while (count){
console.log("while loop!");
count ++;
count = false;

this prints both loops, 3 times the for loop and one true and one false while loop, no hidden loops....


Why do you use the count++ in your while loop?


ahh good question, now when i think about it, theres no need for it, as i progressed ive learnt more, also check a thread i started yesterday on my code not running please


As far as I can see ionatan already gave the answer which is that you're not calling the function in which you wrapped all your code so you need a jb(); at the end of your code.


browser crashes when i call jb();