Lesson 5. syntax error


#1



here is the lesson I am stuck on, https://www.codecademy.com/courses/javascript-beginner-en-ZA2rb/0/5?curriculum_id=506324b3a7dffd00020bf661#

I keep getting a Syntax error: unexpected identifier, and I am absolutely lost as to why I continue to get this error. I have combed over and over the code and can't seem to find where i've gone wrong :confused: Any help is appreciated!!!


var barracks = prompt("you've just built your first rax in TvP and you have scouted that your opponet is going for adept cheese, do you EXPAND, 3 RAX, or CYCLONE RUSH").toUpperCase();

switch(barracks) {
case 'EXPAND':
 var league = prompt("are you a higher league than your opponet (YES OR NO)?").toUpperCase();
 var apm = prompt ("is your apm on the same level as InnoVation?").toUpperCase();
if (league ==='YES' && apm === 'YES') {
console.log("You have all the tools you need to win, go get em tiger!");
} else {
 console.log("yeah, you're screwed. Welcome to TvP where the builds are made up and the Terran always loses!");
}
break;

case '3 RAX':
 var stim = prompt("are you going to rush stim?").toUpperCase();
 var supply block = prompt("did you avoid all supply blocks?").toUpperCase();
if (stim === 'yes' || supply block === 'yes'){
console.log("Marines are too strong! the protoss gets rekt!");
} else {
console.log("G G TASTELESS. you got rekt.");
}
break;

case 'CYCLONE RUSH':
 console.log("ghost pepper all day, er day! they got rekt!");

break;

default:
console.log("G G TASTELESS. you got rekt.");
}

edit: updated code, I think I copied an older draft of the snippet!


#2

you forgot to put the ' : ' after your case '3 RAX'
So far, thats all i can see wrong. Let me know if that helps. Good luck :slight_smile:


#3

I noticed that immediately when I posted this topic. However, when I look at the code I copy pasted from the lesson, its absolutely there, which confuses me further

EDIT: I think I had an old code snippet on my clipboard, I updated with what I currently have in browser for the lesson.


#4

also in your case '3 RAX':

You should have --> if (sim === 'YES' || supply_block === 'YES') instead of what you have.
1. I dont think you can create a var name with space in between so i suggest you use an underscore just as i have done or just use a single name.
2. You 'yes' should be 'YES' because of your .toUpperCase();
Cheers


#5

let me know if you get it to work. Good luck :slight_smile:


#6

i got it to work! Thank you for your help, this had me stuck for close to an hour!!!!

So I switched out the "supply block" for another single name use. When i used the underscore, I was still getting the same error (after changing the yes' to YES').

If anyone knows why this interaction is happening I would love to get some more insight on it! Even though I got the code to pass, I don't fully grasp WHY it passed now as opposed to before. Here is the working code I used

var barracks = prompt("you've just built your first rax in TvP and you have scouted that your opponet is going for adept cheese, do you EXPAND, 3 RAX, or CYCLONE RUSH").toUpperCase();

switch(barracks) {
case 'EXPAND':
 var league = prompt("are you a higher league than your opponet (YES OR NO)?").toUpperCase();
 var apm = prompt ("is your apm on the same level as InnoVation?").toUpperCase();
if (league ==='YES' && apm === 'YES') {
console.log("You have all the tools you need to win, go get em tiger!");
} else {
 console.log("yeah, you're screwed. Welcome to TvP where the builds are made up and the Terran always loses!");
}
break;

case '3 RAX':
 var stim = prompt("are you going to rush stim?").toUpperCase();
 var mauraders = prompt("are you building mauraders?").toUpperCase();
if (stim === 'YES' || mauraders === 'YES'){
console.log("Marines are too strong! the protoss gets rekt!");
} else {
console.log("Mauraders rule the day! the toss QQs about how OP they are");
}
break;

case 'CYCLONE RUSH':
 console.log("ghost pepper all day, er day! they got rekt!");

break;

default:
console.log("G G TASTELESS. you got rekt.");
}

#7

I am glad it worked. Don't stress over it too much. I believe its just because of the invalid username you were trying to use initially. As to why it didn't work with the underscore, i'd imagine you still put a space somewhere there and it didn't work or you needed to refresh your page. Everything you've known still holds true, its part of learning to be confused sometimes, but always good to seek out solutions and understand why.
Stay curious my friend :slight_smile: