10. To learn it, you gotta 'do' it === Explanation please


#1

My code:

var getToDaChoppa = false;
var getToDaChoppa = function(){
do {
console.log("Smeagol is not sleeping on my foot" + getToDaChoppa)
} while(false);
};

getToDaChoppa();

Printed:

Smeagol is not sleeping on my footfunction () {
do {
console.log("Smeagol is not sleeping on my foot" + getToDaChoppa)
} while(false);
}

I've passed to the next lesson, but i would like to know why my code printed the above, and wasn't it suppose to print something else?

Any insight will be much appreciated.

Thank you :)grin:


#2

When you write :
console.log("Smeagol is not sleeping on my foot" + getToDaChoppa)

getToDaChoppa's value is currently a function, so it seems like it's printing the function's code itself
What were you expecting ?

Plus I'm not sure about your recursive use of getToDaChoppa inside the getToDaChoppa function


#3

based on your code i've done it this way:

    var nameIt = true;
    var getToDaChoppa = function () {

    do {
        console.log("Smeagol is not sleeping on my foot")
        nameIt = false;

    } while (nameIt);
};

getToDaChoppa();

do not forget this:

do {
    statement
}
while (expression) ;

#4

Thank you, will make a note of it.

Thanks for the trouble


#5

Makes kind of sense. Thanks :smile: