Why different results?
-
<!-- function test(grade) { if(grade > 70) document.write(" Passed"); else document.write(" Failed"); } document.write("C1 "+ test(65) + "<br>"); document.write("C1 ")+ test(65)+document.write("<br>"); //--> I am getting following results: FailedC1 undefined C1 Failed
-
<!-- function test(grade) { if(grade > 70) document.write(" Passed"); else document.write(" Failed"); } document.write("C1 "+ test(65) + "<br>"); document.write("C1 ")+ test(65)+document.write("<br>"); //--> I am getting following results: FailedC1 undefined C1 Failed
2 things: firstly, put the function above your body tags. then you won't get the first "Failed". secondly, since you're using a document.write in your function, why do you need to put the result of that function - which is nothing, hence the "undefined" - in the first document.write? either your function should return the value (which is why you would then use the first document.write scenario) or you must take the call to the function out of the document.write (as is the case with the second scenario) -- Raoul Snyman Saturn Laboratories e-mail: raoul.snyman@saturnlaboratories.co.za web: http://www.saturnlaboratories.co.za/ linux user: #333298
-
2 things: firstly, put the function above your body tags. then you won't get the first "Failed". secondly, since you're using a document.write in your function, why do you need to put the result of that function - which is nothing, hence the "undefined" - in the first document.write? either your function should return the value (which is why you would then use the first document.write scenario) or you must take the call to the function out of the document.write (as is the case with the second scenario) -- Raoul Snyman Saturn Laboratories e-mail: raoul.snyman@saturnlaboratories.co.za web: http://www.saturnlaboratories.co.za/ linux user: #333298