Code Your Own Adventure 2! (5/6) SyntaxError: missing ) after condition


#1

Hello ! I have a error : SyntaxError: missing ) after condition

var user = prompt("What's your first name?").toLowerCase();

switch(user){
case 'renaud' :
var birthday = prompt("What is your age ?");
if (birthday == 32 || Thirty two ) {
console.log("I confirm you have" birthday " years old.");
}
else if (birthday >= 32) {
console.log("I think you more young.");
}
else if (birthday <= 32) {
console.log("I think you more older.");
}
else {
console.log("I don't understand.");
}
break;

case 'thibaut' :
    var birthday = prompt("What is your age ?");
        if (birthday == 31 || Thirty one ) {
            console.log("I confirm you have" birthday " years old.");
        }
        else if (birthday >= 31) {
            console.log("I think you more young.");
        }
        else if (birthday <= 31) {
            console.log("I think you more older.");
        }
        else {
            console.log("I don't understand.");
        }
break;

case 'fran├žois' :
    var birthday = prompt("What is your age ?");
        if (birthday == 66 || Sixty six ) {
            console.log("I confirm you have" birthday " years old.");
        }
        else if (birthday >= 66) {
            console.log("I think you more young.");
        }
        else if (birthday <= 66) {
            console.log("I think you more older.");
        }
        else {
            console.log("I don't understand.");
        }
break;

case 'marie-claude' :
    var birthday = prompt("What is your age ?);
        if (birthday == 61 || Sixty one ) {
            console.log("I confirm you have" birthday " years old.");
        }
        else if (birthday >= 61) {
            console.log("I think you more young.");
        }
        else if (birthday <= 61) {
            console.log("I think you more older.");
        }
        else {
            console.log("I don't understand.");
        }
break;

default:
     console.log("I do not know you.");
break;

}

I don't understand the problem. I think I closed my parentheses.


#2

Well, there are a couple of mistakes in this code, first of this problem:

if (birthday == 32 || Thirty two )

if you want to compare both to the number and string thirty two, you should tell the program:

if (birthday == 32 || birthday == "Thirty two" )

you need to use compare operators for both, and i assume thirty two is a string, not a variable, so you have to use quotation marks.

Then, when you want to put a variable inside a string, you have to join it with plus signs:

console.log("I confirm you have" + birthday + " years old.");

Now, this is just one example, but i see this mistake couple of times through the code. Fix all of them, if after that you are still stuck, post an updated version of your code


#3

Hi and thank,

As usual, my problem is between my chair and my screen. :sweat_smile:

My new code :

var user = prompt("What's your first name?").toLowerCase();

switch(user) {
    case 'renaud' :
        var age = prompt("What is your age ?");
        if (age === 32 || "Thirty two") {
            console.log("I confirm you have " + age + " years old.");
        }
        else if (age >= 32) {
            console.log("I think you more young.");
        }
        else if (age <= 32) {
            console.log("I think you more older.");
        }
        else {
            console.log("I don't understand.");
        }
        break;

    case 'thibaut' :
        var age = prompt("What is your age ?");
        if (age === 31 || "Thirty one") {
            console.log("I confirm you have " + age + " years old.");
        }
        else if (age >= 31) {
            console.log("I think you more young.");
        }
        else if (age <= 31) {
            console.log("I think you more older.");
        }
        else {
            console.log("I don't understand.");
        }
        break;

    case 'fran├žois' :
        var age = prompt("What is your age ?");
        if (age === 66 || "Sixty six") {
            console.log("I confirm you have " + age + " years old.");
        }
        else if (age >= 66) {
            console.log("I think you more young.");
        }
        else if (age <= 66) {
            console.log("I think you more older.");
        }
        else {
            console.log("I don't understand.");
        }
        break;

    case 'marie-claude' :
        var age = prompt("What is your age ?");
        if (age === 61 || "Sixty one") {
            console.log("I confirm you have " + age + " years old.");
        }
        else if (age >= 61) {
            console.log("I think you more young.");
        }
        else if (age <= 61) {
            console.log("I think you more older.");
        }
        else {
            console.log("I don't understand.");
        }
        break;

    default:
        console.log("I do not know you.");
        break;
}

But exercice is not finished, it miss logical operator 'and' (&&).


#4

What is it with my explanation that people don't understand it? If you use a logic operator (and or or, doesn't matter), in both cases conditions you should check something, this:

if (birthday == 32 || "Thirty two" )

should be:

if (birthday == 32 ||  birthday == "Thirty two" )

you again have to tell that it is birthday you have to check, it could be something else altogether. And i still see this mistake many times in your code, what, in my original explanation wasn't good?