5.) Brad is not defined


#1

Not sure how Brad is not defined when you type Brad into the question that asks what your name is. All others work so I assume it has something to do with my if/else statement. Can't really find the problem so yeah need some help!

var user = prompt("What is your name").toUpperCase();
switch(user) {
    case'BRAD':
        if(Brad&&Stew){
        console.log("That is my name too!");
        } else {
        console.log("Your name is close to my name!");
        if (Brad||Braden){
        console.log("That is my name too!");
        } else {
        console.log("Our names are very close!");}
        break; 
    case'MARK':
        console.log("I know a guy named that too!");
        break;
    case'HANNAH':
        console.log("You have a pretty cool name");
        break;
    default:
        console.log("That is a great name!"); }


#2

this line:

if(Brad&&Stew)

Brad is a variable. Which doesn't exist. Either create a Brad variable, or use a string. And i am not sure what you are comparing it with.


#3

I have looked at a few other examples under the Q/A section for Code My Adventure 2 and that format has not been a problem for others so I am not sure why the case is different here. In either case, I do not believe using a string is required or creating Brad as a variable since the lesson does not lead one to do either of those so it must be something else


#4

yes, if you enter Brad into the prompt, it stores a string Brad into your user variables, but on this line:

if(Brad&&Stew)

you use variables (Brad and stew) which do not exist. Brad and Stew are undefined variable. The problem is in those lines. Brad is a string stored in the user variable, brad is not a variable!


#5

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