Lesson 10 To Learn it You gotta Do it - AND IT SEEMS I JUST CAN"T -do it


#1

Instructions

Write a do/while loop inside the function we've created for you, getToDaChoppa. The function should log a string of your choice to the console. do it now!

<Below this line, in what way does your code behave incorrectly? I
SyntaxError: missing while after do-loop body>

Clearly I just don't get this. PLEASE HELP. I think it should work. Looks like it might work, but I really don't get why it doesn't work. I'm pretty discouraged at this point. Why do the lessons have functions in them that aren't supposed to be used? And when do you know not to use a function and when use a function? I missed that part.
The whole idea of do is to force the code to run once even when the condition is false right?
So for this lesson and for this language as a whole what am I missing? Suddenly I miss SQL...

var getToDaChoppa = function(){
getToDaChoppa = 7

do {
 console.log("Might work, Might not");
}
While (getToDaChoppa <6);
  }
  };

getToDaChoppa();


#2

while should be lowercase.

And please note that } after the while (getToDaChoppa <6); is unwanted. You have nothing to close here.


#3

You ARE Awesome! Thank so much for checking my work. Of course that did it.
I would have stared at it all day. So I do get the concept, just not the syntax.
It's the little stuff and here I was all ready to sharpen razor blades!

Any way I could get a hint on lesson 5 the infinite loop. (after half a day I gave up and moved on.)


//Remember to set your condition outside the loop!
var count = 0

var loop = function()
{
while(count < 3);{

console.log("I'm looping");
count++
}
};

loop();

Crashes every time. At least it's predictable code.


#4

You're very welcome :slight_smile:

Semicolon after the while (or after for, if) terminates the construct. So this is how the interpreter sees your code:

//Remember to set your condition outside the loop!
var count = 0

var loop = function() {
  while (count < 3) {} // <-- infinite loop

  console.log("I'm looping");
  count++

};

loop();

You only need to delete the semicolon after the while:

var count = 0

var loop = function() {
  while (count < 3) {
    console.log("I'm looping");
    count++
  }
};

loop();

#5

Again, you are AWESOME!
It's the little stuff - I'm thinking I don't get the concepts, but syntax is sending me over the edge.
Thank you for taking the time to explain and check my work! My wrists thank you too! (kidding, of course).


#6

You're welcome :slight_smile:

I use many languages and it's hard to remember all the syntax quirks. That is why I (and many developers) use documentations and references. If I don't remember how to write something in the JavaScript I visit the MDN JavaScript docs.

Article about while -> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while


#7

Again many thanks for the reference guide! You are well spring of great information and help.
I've bookmarked the MDN page. I am certain I will be a regular visitor!


#8

Glad I could help! And thank you very much for your kind words :slight_smile:


#9

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