Review of Loops


#1

I'm not sure why, but this following snippet of code doesn't work. I've scoured examples of the FOR loops and it seems to me that it should run. The error is: SyntaxError: unterminated string literal

for (var x = 1; x < 3; x++) {
console.log("I know you got him picked, but the man's in trouble!");
}

Thanks in advance.


#2

Try
n\'s
This is called escaping the character '.


#3

Thanks for the quick reply, , jibblyj. I admit that I thought about this, but that I swear this worked once before because " is not ' So, unfortunately I still get nearly the same error.


#4

What's the new error?


#5

The output I posted in the OP is the same, but Codecademy's error message now states:

"Oops, try again.
There was a problem with your syntax."


#6

You said that this is a snippet, could I see the full code?


#7

for (var x = 1; x < 3; x++) {
console.log("I know you got him picked, but the man\'s in trouble!");
}

var carbon = true;
while(carbon) {
console.log("I've had it!);
} carbon = false;

var carbon = false;
do {
console.log("Do this first!");
} while(carbon);

carbon();


#8

You're missing a closing quote.

That is gonna run forever because you haven't put carbon = false inside the loop.

Is fine but you don't need var in front of carbon at the top.

That's not a function.. Are you supposed to define one?


#9

This is the HINT that they provide:

// Can be false from the start, since
// do/while runs at least one time
var condition = false;
do {
console.log("I'm printed once!");
} while(condition);

So, no is the answer you want.


#10

Could you give me a link to the exercise?


#11

https://codecademy.com/courses/javascript-beginner-en-ASGIv/2/4?curriculum_id=506324b3a7dffd00020bf661#

Thanks again for your patience, jibblyj.


#13

Here is the code that you gave me, after I edited it to pass.

for (var x = 1; x < 3; x++) {
    console.log("I know you got him picked, but the man's in trouble!"); 
}

var carbon = true;
while(carbon) {
    console.log("I've had it!"); 
    carbon = false;
} 

carbon = false;
do {
    console.log("Do this first!"); 
} while(carbon);

Notice to people viewing this topic in search of help: Please, for your sake, don't copy this code. It will benefit your leaning more if you write the code yourself, and learn how it works while you do so. If you just copy my code mindlessly and don't understand what it does, you won't ever learn it.


#14

I've been staring at this since yesterday. I just can't figure out what I did wrong this time (This is the second time running this exercise because I didn't feel very confident with my first effort).

Regarding your cleanup, I saw a semi-colon in the second bit of code, but even fixing that, I still can't get it to go. Yours did work as it did for you. So, what am I missing? Where did I make the mistake?


#15

If you copy the code exactly as it is above, it should pass. I can't find any problems with it.
If it doesn't work, try using another browser as a workaround.


#16

This is bizarre. Copying it into two different browsers works, but my originally typed code doesn't. Clearly the coding gods are unhappy with the frozen yogurt sacrifices I've recently made.

Nevertheless, Thanks so much for helping me with this. I think I'll start over and see if that changes anything.


#17

This is indeed bizarre, but for some reason it happens quite a lot from what I've heard.

That must be the case.

I'm happy to have been of service :slight_smile: