What is the problem with my code?


#1

I am trying to code my own little things where when you enter the website it prompts you for your name then when you enter your name it confirms with you wether your name is short or long. My problem is it keeps saying your name is to short no matter how long I put the name as. Here is the code:

prompt("What is your name?");
var yourName = prompt;

if(yourName > 8)
{
confirm("You have a long name");
}
else
}
confirm("You have a short name");
}


#2

yourName is a string, not a number. However, the length attribute is a number, which is pertinent in this case...

yourName.length > 8

#3

This attempt at getting and storing information from the user needs some rethinking too.

The following asks the user for their name but it doesn't store it anywhere:

prompt("What is your name?");

The following stores the prompt method itself in the variable yourName, it does not set yourName to the user's response to the prompt -- this not what you had in mind.

var yourName = prompt;

You want to get AND store the user's answer to your prompt. You can do that by combining those two lines.

Do you see how you might accomplish that now?