Practice makes perfect


#1


var count = 0;

var loop = function(count){
	while(count < 3){
		//Your code goes here!
		console.log("I'm looping!");
	   
	}
};

loop();

No clue how to complete the objective of making it log im looping 3 times :frowning:


#2

use a counter to stop condition of while loop, and counter should be minus or plus with one. in here you should add one in every step of loop to count.
count = count + 1;

that code must be insert after console.log(...)


#3

Here it is probably better placed before the console.log as it doesn't depend on it.

But yes the general idea is that a (while) loop does a specific task again and again. So to make it work more than once and less than infinite you set up a condition that must be true for the loop to work. Now if your condition is count < 3. You could make it loop 3 times by letting count start at 0 and increase the variables value in every loop:

is count < 3?
count = 0 -> yes -> first loop:
do your stuff
increase count by 1

is count < 3?
count = 1 -> yes -> second loop:
do your stuff
increase count by 1

is count < 3?
count = 2 -> yes -> third loop:
do your stuff
increase count by 1

is count < 3?
count = 3 -> no -> quit loop:


#4

Add an increment counter within your loop. The counter is incremented one each time the loop has completed. Add this under your console.log()

count++;

And another thing, remove the parameter count on your function. On this line:


#5

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