What's my error?


#1

https://www.codecademy.com/courses/javascript-beginner-en-ZA2rb/0/5?curriculum_id=506324b3a7dffd00020bf661#

I'm getting Error: Invalid left hand assignment, and the code isn't running at all


var user = prompt("What's your favorite grocery item?").toLowerCase();
var favColor = prompt("What's your favorite color?").toLowerCase();
var favNumber = prompt("favorite number?");
switch(user) {
    case 'potatoes':
        console.log("Earth apples. Ok, I can roll with that.");
        break;
    case 'sushi':
        var fish = prompt("what kind of fish is your favorite?").toLowerCase();
        if (fish="Salmon" || "tuna") {
        console.log("You would go to the Jewel.");
        }
        else {
            console.log("Ooh, look at Mr. Shmancy")
        };
        break;
    case 'candy':
        if (favColor = "green" && favNumber = "3") {
            console.log("Wow. You're good.")
        }
        else {
        console.log("A man after my father's heart.");
        };
        break;
    case 'nuts and raisins of all sorts':
        console.log("You probably know a little bit about coding. What are the odds that I'll have a switch that matches with exactly that phrase? Come on.");
        break;
    case '1182267398':
        confirm("You got the code! You win the game! Click here for your reward");
        break;
    default:
        console.log("I guess that's ok.");
}


#2

Here is your problem

    if (fish="Salmon" || "tuna") {
    console.log("You would go to the Jewel.");
    }
    else {
        console.log("Ooh, look at Mr. Shmancy") <------- Missing semicolon
    }; <-------Remove as well
    break;
case 'candy':
    if (favColor = "green" && favNumber = "3") {
        console.log("Wow. You're good.") <------and here
    }
    else {
    console.log("A man after my father's heart.");
    }; <-----This semicolon is not needed

#3

Thank you, but it still doesn't work


#4

Could you paste your current code


#5

var user = prompt("What's your favorite grocery item?").toLowerCase();
var favColor = prompt("What's your favorite color?").toLowerCase();
var favNumber = prompt("favorite number?");
switch(user) {
case 'potatoes':
console.log("Earth apples. Ok, I can roll with that.");
break;
case 'sushi':
var fish = prompt("what kind of fish is your favorite?").toLowerCase();
if (fish="Salmon" || "tuna") {
console.log("You would go to the Jewel.");
}
else {
console.log("Ooh, look at Mr. Shmancy");
}
break;
case 'candy':
if (favColor = "green" && favNumber = "3") {
console.log("Wow. You're good.");
}
else {
console.log("A man after my father's heart.");
}
break;
case 'nuts and raisins of all sorts':
console.log("You probably know a little bit about coding. What are the odds that I'll have a switch that matches with exactly that phrase? Come on.");
break;
case '1182267398':
confirm("You got the code! You win the game! Click here for your reward");
break;
default:
console.log("I guess that's ok.");
}


#6

if (fish = "Salmon" || "tuna") you cant put fish = that is a assignment in a conditional expression so try just removing fish = i guess if it is a variable try putting it outside were the other variables are on top

same thing here

if (favColor = "green" && favNumber = "3") {
console.log("Wow. You're good.");
}


#7

So after you've done that try rewriting them to make it work

(fish = "Salmon" || "tuna")

and

(favColor = "green" && favNumber = "3")


#8

what do you mean by "assignment in a conditional expression?"


#9

well here are all the assignment operators

  • =
  • +=
  • and so on
    so for example you cant put x = y in a conditional expression?

Conditional expression on the other hand is an expression so it can tell the computer for example

if ( X && Y)<-- this is a condition {
Do this
};


#10

In the fish prompt, the toLowerCase function is applied. All of the user's inputs are set to lower case. Fish would never be assigned 'Salmon' if that was the user input. It would be turned to 'salmon'.


#11

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