9/11 TypeError: getToDaChoppa is not a function


var getToDaChoppa = false
  // Write your do/while loop here!
      console.log("sucka you in da choppa"+getToDaChoppa+"!");
}  while(getToDaChoppa=0)


ok so when I run this code, my message plays on the console like this: "sucka you in da choppafalse"

but if I leave it as a function, I get an error saying unexpected "do"

I don't get why at the beginning of this, we don't define "getInDaChoppa" as true or false, like we've done with the other loops. Why do some loops have functions and others dont? how does the function interact with the loop?

i don't want to just keep playing around with it until I get it right, I want to understand what I'm doing.. and I'm pretty sure that what I am doing wrong has to do with the function syntax interacting with the do/while loop


this is the construct of the do while loop


you can try something like this

var toDaChoppa = parseInt(prompt("Enter a number: "), 10);

function getToDaChoppa(){
    console.log("sucka you in da choppa"+"!");

}while(toDaChoppa > 0);// your code getToDaChoppa=0 is incorrect

when you call getToDaChoppa() it wrong because it is not a function but a variable


Well right now you are running;


at the end of your code. That's making the console thing "Hey.. That variable isn't a function.. Yo what in the poopnuggets are you doing??? #errorMessagesForLife"



"While" arguably you could do that there are a couple errors with this statement.


"=" signs make a huge difference in how you use them.

One: "=" sign to the console is an assignment operator. Meaning you are trying to tell the while loop to do something while you're ASSIGNING a value. Again it's looking at you like... "What the poop dawg?"

Two and Three: "==" / "===" signs tell the computer "Hey if this thing is equal to that thing then everything is cool, go on your business."

Also note that 0 === false, and 1 === true in JavaScript, and most other programming languages.

} while(getToDaChoppa == 1);


} while(getToDaChoppa === True); <-- Don't forget semicolons

Right now the program is trying to show you that the code will run once whether or not the condition for it to run is actually what you want it to be.

So when if you say "getToDaChoppa = false;"

it's going to spit out the code anyway until it runs into the while condition.

If you put

} while(getToDaChoppa === false);

then it will run through the code infinitely

otherwise if you put:

} while(getToDaChoppa === true);

it'll run through the code between "do" and "while" once to let you run your code no matter what is in the while parameters.


And how dare you reply so quickly... I spent so much time making my reply look pretty :cry:


Your explanation was more in-depth than mine was. Thumbs up :grinning:


@rydan and @lolman really good replies :+1:
Just some remarks one @lolman 's post:

0 === false, and 1 === true

this is actually pretty close but not true. The difference between == and === is that == compares values so yes 0 ==false and 1 == true whereas === compares values and types so as 0 is a number and false is a boolean 0 === false would be false.

And here:

} while(getToDaChoppa === True);

True was probably meant to be true wasn't it?
Still awesome post thanks for helping!
@rydan Didn't know you could make syntax highlights by wrapping it in 3 ` at the beginning and end but looks nice!


ok so here's what I ended up writing:

var getToDaChoppa = function(){
  // Write your do/while loop here!
  console.log ("sucka you in da choppa"+"!");
}while( getToDaChoppa==0);

and it ran it fine.. @rydan I didn't do any parseInt(prompt("Enter a number: "),10); like you suggested, but I just tried it and its cool because the console runs the phrase for the number that you enter.

why did you put 10 next to "enter a number?" is it to have a range between 0 and 10? because even if you enter a number greater than 10 it runs it that number. put in 20 and it printed the phrase 20 times. so in this case, does the number that you enter is define the limit of the loop? like its not an infinite loop because the user enters a specific number and then the console runs it that number of times?

and why do you put -- next to "toDaChoppa"? doesn't -- tell the console to count down one integer at a time when it runs the loop? or is that just for a for loop?

and why are you using the parseInt function for this? whats the purpose of splitting the variable into a whole and a partial?

just a few lil questions. thaynx

while( getToDaChoppa==0);

It's not the best idea to use the function name here, rather use a different variable of which you know the value. Here you compare getToDaChoppa which is a function to 0 which is a number. Unless you know how it behaves and that it is always this way better use values that you know. e.g. as @rydan did use a toDaChoppa variable that handles the condition. Also you might have a look at it again as this do while loop is really a loop as it goes more than once.

On last words to the parseInt function. The problem is that prompt always return strings no matter what you enter in the text field. Even if you enter 42 what prompt outputs is "42" this might be a problem when you compare it. 42 == "42" would be true as the value is the same but as soon as you use === (which compares values and types) you'll get false although you maybe entered a reasonable number just because it is string vs number. For this purpose we have parseInt which translates the string into an integer. I guess there is parseFloat as well for floating point numbers. Now the 10 is there to indicate that you're dealing with decimal numbers (0,1,2,3,4,5,6,7,8,9) so "20" is interpreted as 2*10^1+0*10^0 as you would assume. But this function can do even more if you like binary number you can also translate 111 with parseInt("111",2) to 7. 1*2^2+1*2^1+1*2^0 = 4+2+1 =7 and any other common or uncommon number system.


That is an incredibly simplistic and perfect analogy. I had no idea that that was the major difference between the two and three equals. I thought for all intensive purposes they were the same thing, but I can see how this could be a huge benefit to decipher between correct values, and correct value/types. Thanks for the explaination.


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

console.log("Salut les Zeros");


} while (compteur < 3);