Movie lab (Please Help Me Out)


#1

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.'.


#2

First of all, is this a codecademy task?

From the questions, this

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.";
}

#3

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.


#4

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


#5

Yes, It's not from codecademy.

It's from ANDELA


#6

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?


#7

Wow, so this is an Andelan!? Great!

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


#8

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


#9

Your name in up there brother.


#10

I just googled andela, you are in their program?


#11

This is a new Home Study from ANDELA tho.


#12

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


#13

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


#14

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:


#15

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.


#16

No wahala just give it all your best.


#17

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


#18

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.


#19

Not yet solved ooooooo!!!


#20

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: