Why is this an endless loop?


#1

var getToDaChoppa = function(){
// Write your do/while loop here!
do {
console.log("to learn it, do it");
} while (getToDaChoppa);

getToDaChoppa();

https://www.codecademy.com/courses/javascript-beginner-en-ASGIv/2/3?curriculum_id=506324b3a7dffd00020bf661#


#2

because functions getToDaChoppa evaluated to true:

var getToDaChoppa = function(){
  console.log("function needs to do something")
}
if (getToDaChoppa){
  console.log("functions are true")
}

#3

SO I got it to work with this code:
var getToDaChoppa = function(){
// Write your do/while loop here!
var val = true
do {
console.log("to learn it, do it");
val = false

} while (val);
};

getToDaChoppa();

But I don't really understand why I even need the function. Why do I call a function that has no input parameter?


#4

the function doesn't add much value at this point.


#5

Thanks much!:slight_smile:


#6