0

function can_i_enter(age) if (age < 6) { document.write ("you are not allowed to watch Dead pool after 6:00pm.");} else if (age>=6 && age<17) {document.write("you must be accompanied by a guardian who is 21 or older.");} else if (age>=17 && age<25) {document.write ("you are allowed to watch Dead pool, right after you show some ID. ")} else if (age>=25) { document.write ("Yah! you can watch Dead pool with no strings attached!");} else { document.write ("Invalid age. ");} can_i_enter (24);

31st Aug 2016, 8:42 PM
Dan-Awoh Emmanuel
Dan-Awoh Emmanuel - avatar
9 Respuestas
+ 1
You forgot to put { } around your function block.
31st Aug 2016, 10:17 PM
Zen
Zen - avatar
+ 1
function can_i_enter(age) { if (age < 6) { document.write ("you are not allowed to watch Dead pool after 6:00pm.");} else if (age>=6 && age<17) {document.write("you must be accompanied by a guardian who is 21 or older.");} else if (age>=17 && age<25) {document.write ("you are allowed to watch Dead pool, right after you show some ID. ");} else if (age>=25) { document.write ("Yah! you can watch Dead pool with no strings attached!");} else { document.write ("Invalid age. ");} } can_i_enter (24);
1st Sep 2016, 9:08 PM
Zen
Zen - avatar
0
I tried running this function but it kept returning a blank page as output. the play ground crashes. please guys what is wrong with this code
31st Aug 2016, 8:43 PM
Dan-Awoh Emmanuel
Dan-Awoh Emmanuel - avatar
0
sorry, i don't speak english very good. you should use switch in this function and the wrong look for ";" in the 3° document. write
31st Aug 2016, 10:20 PM
Yepy Perty
Yepy Perty - avatar
0
and missing "{}" of the function
31st Aug 2016, 10:23 PM
Yepy Perty
Yepy Perty - avatar
0
even when I put the {} it wasn't working. please how do I use switch here, cos switch only works for one expression how can I use it for multiple expressions. thanks
1st Sep 2016, 3:03 PM
Dan-Awoh Emmanuel
Dan-Awoh Emmanuel - avatar
0
ok thanks zen. I missed the colon (;). but can switch be used here? I doubt
1st Sep 2016, 11:25 PM
Dan-Awoh Emmanuel
Dan-Awoh Emmanuel - avatar
0
im js noob learner but why u didbt use switch case its easy to read and save time (its just my own opinion)
13th Sep 2016, 1:38 PM
mhennaoui
mhennaoui - avatar
0
Yes, you can :) if/else and switch can be used in the same circumstances, there are no exceptions, because they do exactly the same thing.
24th Oct 2016, 8:17 AM
Ann Salom