Just wondering if my code is fine. (10/11)



My code doesn't behave incorrectly, nor am I stuck. I was just wondering if what I wrote is fine. I always check other's codes when I finish mine to make sure I'm on the right track and I see a lot of people created a new global variable and declared it as false for their while loop condition. The way I saw this exercise was that I could simply call the one given global variable false in the while condition only and it should just work as fine. I've been browsing and always seeing people declare a new variable so now I'm doubting myself whether I was correct or not doing this. I also have a question, in the previous do/while loop, they declared a global variable as false but for this exercise they decided to declare that global variable as a function, why is that? Thanks you in advance if you answer!

var getToDaChoppa = function(){
      console.log("This part should work for sure");
  }while(getToDaChoppa = false)



The above is not a conditional expression. It is an assignment statement which is invalid inside a while condition. But there is another issue, as well. getToDaChoppa is defined as the function. We cannot treat it as a boolean (as a non-empty string it will always be true). Suggest create a different variable and build the condition around that.

Something like this, perhaps?

var getToDaChoppa = function () {
    var condition;
    do {
        condition = false;
        console.log("This part should work for sure");
    } while (condtion);


Hello @xfrenchy,

What you have written is basically fine, apart from a couple of small problems. You haven't defined the variable getToDaChoppa as a boolean, but as a function. Following up on @mtf's point, you have to use a boolean condition (one that equates to true or false) as the condition of your do ... while loop. Hope this clears everything out...


I wonder why it said it was fine and let me keep going. Thanks for the reply!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.