Can someone help me with this code, saying error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can someone help me with this code, saying error

function canIWatch(age) { if (age <= 0) { return "Invalid age."; } else if(age < 6) { return "You are not allowed to watch Deadpool after 6.00pm."; } else if(age < 17) { return "You must be accompanied by a guardian who is 21 or older."; } else if(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

23rd Mar 2017, 5:24 PM
Okonkwo Clovis Chisom
Okonkwo Clovis Chisom - avatar
5 Answers
+ 3
Replace the "else" at the end with a }
23rd Mar 2017, 5:29 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 2
function canIWatch(age) { if (age <= 0) { return "Invalid age."; } else if(age < 6) { return "You are not allowed to watch Deadpool after 6.00pm."; } else if(age < 17) { return "You must be accompanied by a guardian who is 21 or older."; } else if(age < 25) { return "You are allowed to watch Deadpool, right after you show some ID."; } else { return "Yay! You can watch Deadpool with no strings attached!"; } }
23rd Mar 2017, 5:28 PM
SR Praveen Kumar
SR Praveen Kumar - avatar
0
remove the else at the end and close the function with a }
23rd Mar 2017, 5:25 PM
LordHill
LordHill - avatar
0
read the errors it throws. I don't know JS but I threw this into the playground and it doesn't like your unfinished else statement and you didn't close your function
23rd Mar 2017, 5:26 PM
LordHill
LordHill - avatar
0
Try to remove the last "else"! Moreover, one curly bracket missing at the end.
23rd Mar 2017, 5:26 PM
MDT
MDT - avatar