Logical operators


#1


syntax error....Unexpected identifier

var user = prompt("Are you ready to play this game?") .toUpperCase();
var city = prompt("What's your favorite city?","Type your favorite city here.");
switch(city){
case 'Philadelphia':
if(Philadelphia && New York){
console.log("great cities!");
}else{
console.log(" terriable cities!");
if(Philadelphia || New York){
console.log("I've never been there.");
}else{
console.log("My home town!");
}
break;
case 'New York':
console.log("I would love to live there!");
break;
case 'Boston':
console.log("It's too cold in the winter.");
break;
default:
console.log("Every city is great in its own way!");
}

`


#2

This is my new code...what am I doing wrong!

var user = prompt("Are you ready to play this game?") .toUpperCase();
var city = prompt("What's your favorite city?","Type your favorite city here.");
switch(city){
case 'Philadelphia':
var Philadelphia = prompt ("will you come with me?", (Yes or No)").toUpperCase();
var New York = prompt ("would you like to go here instead?", (Yes or No)").toUpperCase();
if(Philadelphia==='yes' && New York==='yes'){
console.log("lets do both!");
}else{
console.log("maybe just one.");
}
if(Philadelphia==='yes'|| New York==='yes'){
console.log("I've never been there.");
}else{
console.log("My home town!");
}
break;
case 'New York':
console.log("I would love to live there!");
break;
case 'Boston':
console.log("It's too cold in the winter.");
break;
default:
console.log("Every city is great in its own way!");
}


#3

Start debugging your code by looking at the error message. If you can't figure it out place your issue here along with the error message and your deductions


#4

I refreshed my code and started over and I'm still getting the same message......Syntax error: unexpected token {

var user = prompt("Are you ready to play this game?") .toUpperCase();
var city = prompt("What's your favorite city?","Type your favorite city here.");
switch(city){
case 'Philadelphia':
var userCity = prompt("What's your favorite city?","Say Philadelphia, Boston or New York").
if(userCity==='PHILADELPHIA' || userCity==='NEW YORK'){
console.log("Those are great cities!");
}else{
console.log("Those are terriable cities!");
break;
case 'New York':
var userPick = prompt("Do you want to go to New York?","say yes or no") .toUpperCase();
if(userpick==='NEW YORK' && userPick=== 'YES'){
console.log("I would love to live there!");
}else{
console.log("Let's never go there!");
break;
case 'Boston':
console.log("It's too cold in the winter.");
break;
default:
console.log("Every city is great in its own way!");
}


#5

Take a look at this link on how to use .toUpperCase:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase

Remove the period after the closing parentheses. It's probably causing the syntax error.

When you write a code block for an else statement, you start and end it with curly brackets. The latter is missing here.

Same error as above.

I am no expert in writing code for games. If I could offer some advice beyond syntax problems, I would recommend swapping your text string for var city with the one for var userCity. This way, the user answers with one of the city names you have written if/else statements for. Then remove the var userCity prompt altogether and swap the userCity variable out with city in the corresponding if/else statement for case 'Philadelphia'.

example:

BECOMES

var city = prompt("What's your favorite city?","Say Philadelphia, Boston or New York");
case 'Philadelphia':
if(city==='PHILADELPHIA II city === "NEW YORK'){

Hope this helps :slight_smile:


#6

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