Code adventure 2 - partially working


#1

I wrote the following however it simply prints the default always not matter how I answer the first question? clearly I have an issue but not sure what it is? any help appreciated.. TY

var user = prompt("How are you").toUpperCase();
switch(user) {
case'Loving life':
var life=prompt("Are you loving life (yes or no)").toUpperCase();
var loc=prompt("what city? Boston or Phoenix?").toUpperCase();
if(life==yes && loc==boston){
console.log("you love boston");
}
else
{console.log("You need more sun" );
}
break;
case'bored':
var ski=prompt("do you ski? (yes or no)").toUpperCase();
var hike=prompt("do you hike (yes or no)").toUpperCase();
if(ski==yes || hike==yes){
console.log("You should move to Denver");
}
else
{console.log("You should find a beach!");
}
break;
case'cold':
var coast=prompt("Which do you prefer Phoenix or Miami?").toUpperCase();
var water=prompt("do you like water (yes or no)").toUpperCase();
if (coast==Miami && water==yes){
console.log("Miami is a place for you");
}
else
{
console.log("visit phoenix");
}
break;
default: {
console.log("move to LA");
}
};


#2

Hello,

if(life==yes && loc==boston)

Aren't you trying to compare the variable life to "yes"?

if(life=="yes" && loc=="boston")


#3

yep I am, I see I missed the " quotation marks. I added them but still always writing out the default. I'm reviewing for other issues... thank you for the tip


#4

I also discovered I was using the to.UpperCase when I should have been using to.LowerCase. I re-wrote my code a bit and now it works perfectly:

var user = prompt("How are you").toLowerCase();
switch(user) {
case'loving life':
var age=prompt("what is your age?)").toLowerCase();
var loc=prompt("what city do you live in?").toLowerCase();
if(age>=40 && loc=="boston"){
console.log("boston is pefect for you");
}
else
{console.log("hartford could work");
}
break;
case'bored':
var ski=prompt("do you ski? (yes or no)").toLowerCase();
var hike=prompt("do you hike (yes or no)").toLowerCase();
if(ski=="yes" || hike=="yes"){
console.log("You should move to Denver");
}
else
{console.log("You should find a beach!");
}
break;
case'cold':
var temp=prompt("what is temperature in your city?");
var water=prompt("do you like water (yes or no)").toLowerCase();
if(temp<= 32 && water=="yes"){
console.log("Miami is a place for you");
}
else
{
console.log("Stay put");
}
break;
default: {
console.log("Live life be happy");
}
};