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);
9 Antworten
+ 1
You forgot to put { } around your function block.
+ 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);
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
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
0
and missing "{}" of the function
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
0
ok thanks zen. I missed the colon (;). but can switch be used here? I doubt
0
im js noob learner but why u didbt use switch case its easy to read and save time (its just my own opinion)
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.