Not Getting the Response I Expected


#1


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


When I select "girl" after choosing dwarf, it still prints the response for "boy" to the console. Can anyone tell me what I'm missing. Other than that, everything seems to work.


var user = prompt("Choose your race. (Human, Goblin, Dwarf, Elf, or Halfling)").toUpperCase();

switch(user){
    case 'HUMAN':
        console.log("Ah, a human...how boring.")
        var gender = prompt("Are you male or female?").toUpperCase();
        var humanClass = prompt("Choose your class: THIEF, WIZARD, or WARRIOR.").toUpperCase();
        
        if(gender === 'MALE' && humanClass === 'WARRIOR'){
            console.log("Ah, yes! A strapping young Warrior!")
        }
        else if (gender === 'FEMALE' && humanClass === 'WARRIOR'){
            console.log("What a fierce Warrior, you are!")
        }
        else if( gender == 'MALE' && humanClass === 'THIEF'){
            console.log("You look like quite the rascal, thief!")
        }
        else if( gender == 'FEMALE' && humanClass === 'THIEF'){
            console.log("You are awfully pretty for a thief!")
        }
        else if (gender == 'MALE' && humanClass === 'WIZARD'){
            console.log("Funny, you don't look like Gandalf")
        }
        else if (gender == 'FEMALE' && humanClass === 'WIZARD'){
            console.log("I believe you are technically a  Witch, technically speaking...")
        }
        else{
            console.log("Not one to be defined by your gender, I see.")
        }
    break;
    case 'GOBLIN':
        console.log("Hmmm I never trust a Goblin.")
    break;
    case 'DWARF':
        var dwarf = prompt("Are you a boy dwarf or a girl dwarf? I can never tell the difference!").toUpperCase();
       if(dwarf === 'MALE' || 'BOY'){
           console.log("You look just like Gimli!")
       }
       else if (dwarf === 'FEMALE' || 'GIRL'){
           console.log("Of course, you're a girl Dwarf...")
       }
       else{
           console.log("I have a perfectly legitimate reason for asking, you know!")
       }
    break;
    case 'ELF':
        console.log("Oh goodie, an Elf. Do you know Legolas?")
        var specialty = prompt("Do you prefer ARCHERY or SORCERY?").toUpperCase();
        if (specialty === 'ARCHERY'){
            console.log("Archery, you must know Legolas!")
        }
        else if (specialty === 'SORCERY'){
            console.log ("Sorcery, hmmm...Are you a good witch or a bad witch?")
        }
        else{
            console.log("Did you forget your glasses?")
        }
    break;
    case 'Halfling':
        console.log("What's a Halfling doing so far away from the Shire?")
    break;
    default:
        console.log("You don't read so well, do ya?")
}


#3

Hi @natefore,

Is this within a switch statement? Only issue within the visible code I see is that there are no semicolons at the end of each console.log, which should break your code. However, if this isn't the issue, I'd ask that you please try posting your full code. Thanks.


#4

Rather than saying or "BOY", and or "GIRL", it should say or dwarf === "BOY", dwarf === "GIRL"

The if condition evaluates two booleans, so each side needs to evaluate to true or false. Though strings are truthy statements, you are saying if true/false OR "BOY/GIRL".
Does this make sense? I'm not great at explaining it, so basically you just need to make sure your testing for variable being equal to a string on both sides of the evaluator. :slight_smile:


#5

@bibleman13

else if is valid in JavaScript, while elif is valid for Python.


#6

Ahh sorry. I have been python lately so I guess I let it slip through the crack xD


#7

I know that feeling! It's so hard to go between so many similar OOP like Python, JS, Java, and Ruby.


#8

Well and I will answer mutliple coding languages (hopefully) in a day so I know what I am talking about I just forget which one I am doing for a minute xD But yeah it is.


#9

I updated it with my full code, I didn't realize I needed to add ";" after all my console.log(s). Thanks


#10

Yep. That solved it?


#11

It didn't solve my issue, but I appreciate the feedback. I wasn't sure if I needed the semi-colons or not. Everything seems to work when I select Human or Elf but Dwarf prints "You look just like Gimili!" no matter what I enter.


#12

Okay, it took me a minute but I get what you are saying now. This solved my issue, thanks a lot!


#13

Awesome! Sorry it took you a while, I know I'm not the best at explaining things haha. :slight_smile: I'm glad it solved your problem, I was starting to second guess myself.


#14

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