Fight case does not work


I was coding using the troll idea that Codecademy used as an example (with my own variations) but the fight case is not working. Everything works fine except for the fight case. For some reason it always displays the victory message, "You defeated the troll and claimed the treasure across the bridge!". Someone please help me! Thank you in advance to anyone who takes the time to help.

var user = prompt("You run into a troll on a bridge, do you fight, pay or run?").toUpperCase();
switch(user) {
        var userStrength = prompt("Are you strong?").toUpperCase();
        var userIntelligence = prompt("Are you smart?").toUpperCase();
        if(userStrength === "YES"){
            userStrength = true;
                userStrength = false;
                if(userIntelligence = "YES"){
                    userIntelligence = true;
                        userIntelligence = false;
                        if(userStrength || userIntelligence){
                            console.log("You defeated the troll and claimed the treasure across the bridge!");
                                console.log("The troll knocked you out!");
        var userMoney = prompt("Do you have money?").toUpperCase();
        if(userMoney === "YES"){
            userMoney = true
                userMoney = false
        var userSpending = prompt("Do you want to spend that money to cross the bridge?").toUpperCase();
                if(userSpending === "YES"){
                    userSpending = true
                        userSpending = false
                            console.log("You pay the goblin and he lets you cross the bridge. You then claim your treasure.")
                                console.log("You refuse to pay the goblin but he steals your money and does not let you cross the bridge anyways!")
                            console.log("You cannot afford to pay the goblin so you head back home.")
        console.log("You ran all the way home!")
    console.log("Please type in only options fight, pay, and run.")


this line

if(userIntelligence = "YES")

you are checking the variable so you have to use == or ===
we use = for assignment.

and next this line

if(userStrength || userIntelligence)

use && operator instead of ||

check this Link


Thank you so much. I didn't see that I was using only 1 =. I fixed it and now the code works. Btw on this line

if(userStrength || userIntelligence)

I meant to use the OR operator.


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