Why do I need this function? LESSON 10


Sorry if this has been answered before, if there's a search function then please let me know.

var getToDaChoppa = function(true){

do {
console.log("Get to the chopper!");
} while (getToDaChoppa = false)



I'm lost. What am I supposed to define as the input for the function at the top? From what I understand, I'm making getToDaChoppa true (or 1) then telling it to print my string and decrement getToDaChoppa by 1 (making it 0 or false) then check that it is false and if it is, stop running. But then what the ■■■■ do I use as my input when I call the function?!

It seems CodeAcademy thinks that giving me a single example of a simple, functionless do/while loop is enough for me to understand how exactly to use functions with it. I've tried tons of combinations of true, false, 0 and 1 in all the various places and thankfully no infinite loops but a lot of 'unexpected true' or 'There's a problem with your syntax' errors. I've also read the explanation in lesson 9 about 50 times and it hasn't helped.

Sorry for the essay, I'm just getting very frustrated that CodeAcademy doesn't actually tell me where I'm going wrong so I can learn from my mistakes


I figured it out. I have to set getToDaChoppa to accept numbers. However I still don't understand why.


Ok it seems like you're not really understood the concepts of functions and loops but just try to make it run according to a mixture of examples.

Maybe first take this post:

as a brief review on functions, feel free to ask if you have any questions about it.

One thing you could get from it is that the function here is really just a framework for running your code and if you'd wanted to you would not even need to bother about it but could just write your code inside of its {}. So it's not about a complex mixture of functions and loops but just about a loop the function is just framework that is not that important at all. (Again take a review if functions are no longer present)

On loops I'd recommend having a look at this:

There are also examples on what loops could look like aso.

Last but not least a list of bugs in the code:
- usage of true instead of a parameter
- using function name as a variable inside the function is at least considered bad habbit
- trying to decrement function getToDaChoppa--; (impossible -> NaN)
- overwriting the function with a value of false getToDaChoppa = false

I guess it is enough for now. As said I'd highly recommend that you review the concepts. Also to debug your code it would make sense to write down what you expect your code to do. Maybe that makes it easier to figure out whether you want to work with true and false or numbers or something different.

Good Luck and if you have questions feel free to ask!