10 Why doesn't this count down?


#1

var tid=0
var getToDaChoppa = function(x){
tid=x;
// Write your do/while loop here!
do
{

  console.log("GETODACHOPPA");

}
while (tid>0);
console.log("COMING IN " + tid)
tid--
};

getToDaChoppa(3);

It crashes the browser and if i change > to < it doesn't count down :confused:


#2

The do...while statement creates a loop that executes a specified statement until the test condition evaluates to false

You didnt dekrement in your loop. That means you create there a so called infinitely loop!
And this crashes your browser

Your code should look like this :slight_smile:

do
{

  console.log("GETODACHOPPA");
  tid--
}
while (tid>0);

#3

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