8. when to while and when to for problem


#1

I am having some trouble trying to print out the 'for' side
Im only able to get the first part to print out
var i = 1;
var loop = function (){
while (i < 2) {
console.log ("hello");
count += 1;
} }
loop ();

for (var j = i + 1; j < 3; i++) {
console.log("yolo");
}


#2

@lightattheend I believe your issue is because you already declared "i" as a variable and are trying to add it to one when saying what "j" is. Now I am not sure if this is the issue but try to change your for loop to

for(var j = 0; j < 6; j++)

The other place that might be incorrect is you declared j as the variable in your for statement but are adding 1 to i not j, another solution may be

for(var j = i + 1; j < 3; j++)

Either of these may be the solution, try both to see if they work.


#3

I tried both and they did not fix it =P


#4

@lightattheend may you tell me the error message that pops up so I may know a more precise field to observe?


#5

found the problem loop (); was causing it


#6

@lightattheend I am glad you found the answer to your own problem! :smiley:


#7

i have been stuck on this problem for a week trying to find the problem i asked friends and they didn't know ._.


#8

whats wrong with the loop();
could you help me please


#9

@datajumper36640 take out the loop(); then it should work fine.