0
Why does the code print undefined?
function gainAcess(gender,age) { if ((gender=="male") && (age>=18) || (gender=="female") && (age>=18)) { document.write("Access is gained"); }else if((gender=="male") && (age<18) ||(gender=="female") && (age<18)){ document.write("Access is lost");} } document.write(gainAcess("female",24));
2 odpowiedzi
+ 6
Because the function doesn't return anything. If you want to write the output, return that output instead of writing it -- otherwise just call it instead of writing the result of the call. (too many writes, cut out one side):
function ... {
writes
}
gainAcess(...)
----- or:
function ... {
return "what to print";
}
document.write(gainAcess())
+ 1
Thanks a lot.It worked with return statement :)))