Hey @mc_yemi_ako! These are your errors first of all you forgot to close your brackets of the function. So i f we get that out of the way second you dont call a function by doing while(functionname()); Its like this getToDaChoppa(false);
Last of all in the specific ecercice its asking you to put it in all together like this:
var getToDaChoppa = function(){
do {
console.log("You've just been pwned!");
getToDaChoppa = true;
} while(something);
};
// And then as i stated above this is how you call the funcion.
getToDaChoppa();
Why do you pass an argument in your function? Don’t, just make a variable and set it to true:
var getToDaChoppa = function(){
my_variable = true;
do {
console.log("Congrats! You are becoming good at programming!");
// set my_variable to false
} while(my_variable);
};
getToDaChoppa();
you still need to set my_variable to false in the loop, otherwise you have a infinity loop. (just like you have now)
You could do this with passing an argument into the function, here is an example:
function myFunction(x){
do {
console.log("hello world");
x = false;
} while (x);
};
myFunction(true);
now, you give the function an argument (i called it x, i wouldn’t call it true of false), then when i call the function, i give x a value of true, then in the loop i set x to false. You could it this way as well.
Correct me if I am wrong but the (true) in this case will make the solution infinite and the false eventually stops the equation after the solution is found? Just like the heads & tails lesson earlier on? I also dream to be a great coder some day, so please help me understand a bit clearer
stetim94 can you explain the ‘my_variable’ part of the code? I don’t where it comes from or what is suppose to relate to?
var getToDaChoppa = function(){ my_variable = true;
do {
console.log(“Congrats! You are becoming good at programming!”);
// set my_variable to false
}while(my_variable);
};
getToDaChoppa();
you still need to set my_variable to false in the loop, otherwise you have a infinity loop. (just like you have now)
If you are stuck on this problem and your browser keeps crashing, it is probably because you are in an infinite loop. Check your parameters and look closely at where your variables are declared.
var getToDaChoppa = function(){
// my sentence will print once, then my variable decision will be set to false, then my while loop will check for the condition to see if it is true (it is false) so the loop is not run and the function ends.
do {
console.log(“Deploy thousand-year back hair!”);
decision = false;
} while(decision);
};
Will this code work? I don’t want to crash my browser!
var myCondition = false;
var getToDaChoppa = function(){
// Write your do/while loop here!
do {
console.log("Will this " + myCondition + "loopCondition work?");
} while (myCondition);
};
getToDaChoppa();
Yes, that will work. the do section execute once, then the while condition gets checked, which is false, loop ends, function ends, you pass the exercise
well, your function takes in an argument (a), when you call this function, you pass a value to this argument, you can see this:
var getToDaChoppa = function(a){
console.log(a)
do {
console.log("test");
a=false
} while (a);
};
getToDaChoppa(true);
As you can see, a is true, since you define that in your function call:
getToDaChoppa(true);
This allows you to pass argument (seem them as variables, into your function so function can behaved different depending on the arguments you feed the function when calling the function
Thanks, this is helpful. It still seems strange to me that you use the parameter (a) instead of the variable. My brain wants to write } while (getToDaChoppa);, since that is the variable.