Movie lab (Please Help Me Out)

This is my question:

Write a JavaScript function named canIWatch that will take age as a parameter.

If the age is less than 6, return You are not allowed to watch Deadpool after 6.00pm.

If the age is 6 or more but less than 17, return You must be accompanied by a guardian who is 21 or older.

If the age is 17 or more but less than 25, return You are allowed to watch Deadpool, right after you show some ID.

If the age is 25 or greater, return Yay! You can watch Deadpool with no strings attached!.

If the age is invalid, return Invalid age.

This is my solution:

function canIWatch(age){
if(age < 6){
return “You are not allowed to watch Deadpool after 6.00pm.”;
}
else if(age >= 6 && age <= 17){
return “You must be accompanied by a guardian who is 21 or older.”;
}
else if(age >= 17 && age<= 25){
return “You are allowed to watch Deadpool, right after you show some ID.”;
}
else if(age >=25){
return “Yay! You can watch Deadpool with no strings attached!”;
}
else{
return “Invalid age.”;
}
}

Here is the error message:

Total Specs: 5 Total Failures: 1
.
canIWatch tests should return an appropriate message if provided age is invalidExpected ‘You are not allowed to watch Deadpool after 6.00pm.’ to equal ‘Invalid age.’.

First of all, is this a codecademy task?

From the questions, this [quote=“ibmbng, post:1, topic:58045”]
else if(age >= 6 && age <= 17){ return “You must be accompanied by a guardian who is 21 or older.”;}
[/quote]

is not the right interpretation for this question

This should be

else if(age >= 6 || age < 17){
return "You must be accompanied by a guardian who is 21 or older.";
}

This too

else if(age >= 17 || age < 25){
return "You are allowed to watch Deadpool, right after you show some ID.";
}

Thank you Bayo.

The && operators is what should be used because both sides must be true.

If you can run the code you will definitely get me right.

I sincerely appreciate your effort on this.

I don’t think it’s codecademy. Nothing aside from this topic comes up when you search for “canIWatch”.

Yes, It’s not from codecademy.

It’s from ANDELA

Erhhmmm… I did run with both. I was only trying to interpret as it is so I played a quick one.

If I have the test cases, I could more precise.

So, is it solved now?

Wow, so this is an Andelan!? Great!

[I was surprise you got my name. Nice!]

1 Like

Yeah, I didn’t think so too! It’s quite a while I completed the JS course and I needed to be sure.

1 Like

Your name in up there brother.

I just googled andela, you are in their program?

1 Like

This is a new Home Study from ANDELA tho.

Surely, i am and i still have many more questions to be completed.

1 Like

I look forward to learning from your shared code, congratulations on being accepted to Andela. :slight_smile:

Haha… You figured that out because you are from this region. :slight_smile:

Hope to learn from your shared code too, just as @biff75. :slight_smile:

1 Like

Yup, thanks bro but am still not in their circle yet. I applied late for the first time. This is the second application i made and i still have much time to round up every assignment. I really want ANDELA like anything.

No wahala just give it all your best.

I hope you get it. This code you shared is from an application then?

1 Like

I will surely get it right trust me i need some time to. I know what am doing i just always like to share knowledge.

1 Like

Not yet solved ooooooo!!!

else if(age >= 6 && age <= 17){ // remove the = sign after < and before 17
    return "You must be accompanied by a guardian who is 21 or older.";
}
else if(age >= 17 && age<= 25){ // remove the = sign after < and before 25
    return "You are allowed to watch Deadpool, right after you show some ID.";
}

If the age is 6 or more but less than (meaning just <) 17, return You must be accompanied by a guardian who is 21 or older.

If the age is 17 or more but less than 25 (same as above), return You are allowed to watch Deadpool, right after you show some ID.

If you did what @bayoishola20 said about && => ||, then this should work.

Also, good luck getting into Andela! :smiley:

2 Likes