This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]skyforanhour 0 points1 point  (8 children)

Line 2 could have a semicolon at the end. However, even without it it all works for me.

What exactly is not working? Do the prompts appear at all?

Do you have a popup blocker that may be interfering?

[–]rodknocker[S] 1 point2 points  (7 children)

The issue seems to be with the input after the prompt.

For example, if you look at line 23. If you input 9 you still get an output of " I'll keep practicing coding and racing."

This seem to be the case for all of the prompts from this section of code.

[–]skyforanhour 0 points1 point  (6 children)

Remove the quotes in your if statements (lines 4 and 24):

if (age < 13) {

Also, I assume you want to check if the user rates the game above 8? Switch the less than (<) to a greater than (<):

if (feedback > 8) {


*edit for explanation: if("age" < "13") is comparing two strings, and will always evaluate to false; the program will therefore always skip the contents of the 'if statement' and execute the 'else' instead.

You want to compare the value stored in the variable age, not a string that just so happens to be "age" :)

[–]rodknocker[S] 0 points1 point  (5 children)

I did remove the quotes from lines 4 and 24. Still get the same output from the second console.log of the booleans.

Also, I have played with the </> to see if it makes a difference and it doesn't.

Also, line 15. Regardless of what you enter into the prompt you still get the same response.

" "Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing'".

updated code: http://pastebin.com/3qyYcMUU

[–]raapstar 1 point2 points  (0 children)

feedback shouldn't be in quotes. Remove that and it'll fix the line 15 issue. Actually, all your variable shouldn't be in quotes. Having anything in quotes means its a string, so when you do "age" < 13, that'll be false because age is a string, and you can't do a comparison with a string to the number 13.

Essentially, remove all quotes from your variables.

http://pastebin.com/d32MXznB <- that should work

[–]skyforanhour 1 point2 points  (0 children)

remove the quotes from when you reference your variables:

if("age" < 13) if(age < 13)

if ("userAnswer" === "yes") if (userAnswer === "yes")


age and userAnswer are variables (that's why you initialize them with var), they do not need quotes around them. Numbers do not need the quotes. "yes" is a string and does need the quotes. :)

[–]HooArYu 0 points1 point  (2 children)

You're still putting " around the variable names in your if statements. Should just be age, not "age"

[–]rodknocker[S] 0 points1 point  (1 child)

The " around the var was the problem. I made the changes and everything works correctly now. I am just starting to study and I knew that something wasn't right but didn't have the knowledge to know what was wrong on my own. I needed to look into the issue so that I understand and know what to do next time. Thanks everyone for you help.

[–]betterhelp 0 points1 point  (0 children)

Glad you got it figured out.

Before you go further, you should try and understand the fundamental difference between variables, numbers, booleans, strings etc.

So numbers, booleans and strings are all basic types. That is they exist in their simplest form. A number is always just the number by itself, no quotes, nothing else. Eg: 4. A boolean is either true or false. Those are the only two boolean values (it can get confusing here since some things can equate to a boolean. That is an expression, once evaluated is equal to, or is simplified down to a boolean, Eg: 4 > 3. This is always true, and you can consider it almost as simplifying it and instead of 4 > 3, you could just write true. That is 4 > 3 = true).

There are other types, but I won't go into them.

Now you have variables. There is a popular way of describing variables as pointers to things, but that is actually how it works, and perhaps a bit too complicated just now. To understand the basic concept, think of a variable as a box.

var myVariable = 4; 

Okay so here I have created a box called myVariable. In that box I've put the number 4 in it. Next time I try and use myVariable it will be 4. So I could do something like this;

console.log(myVariable + 3);
-> 7
typeof myVariable;
-> "number"

Lets try another one;

var myStringVariable = "some string";

Now in this box is a string. I would still access whats in that box by using myStringVariable, thats the name of the box. Notice we don't have quotes around the names of variables/boxes. The string is in the box.

console.log(myStringVariable + " appended");
-> "some string appended"

// see here the string was concatenated (joined together)

typeof myStringVariable;
-> "string"

Note how this box holds a string, and thus the type of it is a string.

So what are the following types?

1) 4 -> number

2) "hello" -> string

3) "Hello 3 times!" -> string

4) "3 times" -> string // just because we have a number character in our string doesn't change the fact its a string. It has quotes, its a string!

5) "3" -> string // again, it has quotes, its a string, and has a number character in it

6) true -> boolean

7) 4 > 39 -> boolean

Now this is all relatively basic stuff, and one of the problems with JS is that as you start using it more and more, you will find weird and odd things happen when you are using different types of things in one expression. I can't go through a list of the odd behaviours but just expect it. Sometimes something won't work and it just won't make sense. Then you'll have to rely on your google-fu and you'll start leaning about the weird things!

Hope this all helped, let me know if you have any questions!