'while' loops in JS - to learn it you got to 'do' it


#1

Guys I am a bit lost form the beginning here! Please can someone kick start me with this one...

var getToDaChoppa = function();

};

getToDaChoppa();

  • I don't know where to start as the example before hand starts var loopCondition = false;

#2

Start by writing the correct syntax...

var getToDaChoppa = function() {  // <<<

};

Note the removed semi-colon which does not belong, and the added opening curly brace on the function body.


#3

Hi, thank you - i have been fiddling with this one for a while and i cannot grasp it.
The below is as far as i've got but i do not know whether the "do" is correct and or what to put in "while"

var getToDaChoppa = function(){
do {
console.log("I am the Terminator");
} while();
}
getToDaChoppa();

for obvious reasons it return - Oops, try again. There was a problem with your syntax.


#4

If you want the loop to stop at some point, a variable will need to be defined and tested in the while()

var condition;
do {
    // some code to run
    condition = false
} while (condition);

#5

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