5. Logical Operators: 'Syntax Error: Unexpected Token Case'


#1

//

var user = prompt("Ready to play? 'Y' for yes, 'N' for no, 'M' for Maybe").toUpperCase();

switch(user) {
case 'Y':
var game = prompt("Do you want to play an RTS game called SC? Y/N?").toUpperCase();
var SC = prompt("Can you play as Terran?").toUpperCase();
if(game === 'Y' && SC === 'Y'){
console.log("See you battle.net, channel apex.");
}
else {
console.log("Ok Noob, play Zerg or Protoss then.");
break;
case 'N':
var girls = prompt("Do you want to go meet some girls instead? Y/N?").toUpperCase();
var nervous = prompt("Are you comfortable with meeting new people? Y/N?").toUpperCase();
if(girls === 'Y' || nervous ==='Y'){
console.log("Doesn't matter, let's go talk to some girls!")
}
else {
console.log("-_- ok... then what do you want to do?")}
break;
case 'M':
var walk = prompt("Do you want to go for a walk and think about what we are gonna do? YES or NO").toUpperCase();
var beach = prompt("Do you want to go to the beach route? Y/N?").toUpperCase();
if(walk === 'Y' && beach === 'Y'){
console.log("Ok let's grab some water bottles and go!")
}
else {
console.log("Ok, let's just chill until we both feel like doing something.");}
break;
default:
console.log("I didn't understand your choice, Y/N/M?");
}
}

//

I think there is a little error somewhere but I can't pin point it. I've checked over a dozen times now. I'd also like to see if it could be put together more efficiently and/or easier for the next programmer to read. Any Tips on that would also be useful

Thanks!


#2

Advice: try to organize your code.....later you will just see what makes it error.


#3

could you provide me a reference to what an organized code looks like? That would help me do some reverse engineering in my learning process and build better habits.


#4

http://code.tutsplus.com/tutorials/top-15-best-practices-for-writing-super-readable-code--net-8118

access this site may it helps :wink:


#5

Thanks, this is already helpful. I'll study it