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