Stuck on Intro to 'While' Loops in JS


Write a while loop that logs "I'm looping!" to the console three times. You can do this however you like, but NOT with three console.log calls. Check the Hint if you need help!

var loop = function(){
//Your code goes here!


-I have no clue where to start. The hint says:
We actually know we need to loop three times, so we could use a for loop, but we'll use while this time.

If we create a variable called count and set it to 0 outside the loop (on line 2), then do count++ each time we console.log() inside the loop, we'll be able to track how many loops we've made. If we set the while condition to be count < 3, that should do the trick!

-but im still stuck. Please help.


//count set to 0 outside the loop
var count = 0;

var loop = function(){
	while(count < 3){ //sets the count less than three having set it = 0
		//prints the string to show how many loops. Count is now 0,1,2
		console.log("I'm looping!"); count++;

loop(); //call the function

Hope this helps! :slight_smile:


Yes, it worked and your explanation definitely does help! Thank you!


You're welcome.

Have fun coding! :slight_smile:


Thank you!! I didn't even have to post and your explanation was exactly what I needed! Thank you!


You're welcome.

Have fun coding! :slight_smile:


thank you it really helped.:yum:


You're welcome @oscarabundez.

Have fun coding! :slight_smile:


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