7. Introduction to 'While' Loops in JS : code is bad but still works


#1


7. Introduction to 'While' Loops in JS

My code is obviosly flawed, but i can't figure out how. The code is accepted, but no text pops up

var count = 0

var loop = function(pennis){
	while(loop === true){
		//Your code goes here!
     console.log(loop)
     count++
		loop === false;
	}
};

loop("I'm looping!");
Replace this line with your code.


#2

Your loop will never run because you are trying to evaluate your function name,

alternatively you can write,

looper = true
while (looper) { //this also works

the inside your loop you should console.log

and finally set the looper variable to false after that line,

looper = false //only one equal sign required


#3

var count = 0

var loop = function(pennis){
while(loop){
//Your code goes here!
console.log(loop)
count++
loop = false;
}
};

loop("I'm looping!");


#4

Stop referring to your function name,

define a variable inside your function that contains the value of true and then negate it inside your while loop. And if you want to console.log

you must refer to your parameter name in your function not loop your function name.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.