10. why is this true?


#1

var getToDaChoppa = function(){
// Write your do/while loop here!
do {
console.log("this is it");
}
while(getToDaChoppa = i);
};
var i = false

getToDaChoppa();

and this isnt:

var getToDaChoppa = function(){
// Write your do/while loop here!
do {
console.log("this is it");
}
while(getToDaChoppa);
};
var i = false
getToDaChoppa = i
getToDaChoppa();


#2

Neither of these are proper ways to create a loop. Example:

do {
var cond = false;
console.log("Inner loop.");
console.log("I will execute once.");
} while (cond);
console.log("Outside of loop now!");

#3

so how to do it using what they gave?


#4

They didn't give anything.

You only have to create your own do-while loop.


#5

They didn't give anything. this is the key .thank you


#6

Hi!

Your first example is true because your telling getToDaChoppa to be i, which it is the whole time no matter if i is true or false. Thats my take on it atleast.

I played around with the code also a bit and added some extra features for the heck and practice.

var choppa = 1;

var getToDaChoppa = function(){
// Write your do/while loop here!

do {
var eta = 11 - choppa;
console.log("I'm getting there in " + eta + "!");
choppa++;

}  while(choppa < 11);

console.log("Elvis have left the building!");
};

getToDaChoppa();


#7

it says unexpected token ; thanks

/* var getToDaChoppa = function(){
  do {
      var xyz = 1;
      console.log("abc");
      xyz++;
     }
     while (xyz <5);
}  
  
};

getToDaChoppa(); */

#8

You have a closing } too much, also why is this written as a comment?


#9

it is written as a comment since i was doing the html class and there was a problem posting html code on the forum.
i tried deleting the } but it freezes my browser. thanks.


#10

With the formatting described here:


You should be able to post code.

About the freezing page. Well you have an infinite loop:

  do {
      var xyz = 1;
      console.log("abc");
      xyz++;
     }
     while (xyz <5);

loop1:
declare variable xyz and set it to 1 ->1
console.log abc
increase the value of xyz by 1 -> 2
check if xyz is smaller then 5 -> true

loop2:
declare variable xyz and set it to 1 ->1
console.log abc
increase the value of xyz by 1 -> 2
check if xyz is smaller then 5 -> true

loop3:
declare variable xyz and set it to 1 ->1
console.log abc
increase the value of xyz by 1 -> 2
check if xyz is smaller then 5 -> true

...

as you can see resetting xyz to 1 in every loop prevents the loop from ending.