Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Why different results?

Why different results?

Scheduled Pinned Locked Moved Web Development
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rgoyal
    wrote on last edited by
    #1

    <!-- 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

    R 1 Reply Last reply
    0
    • R rgoyal

      <!-- 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

      R Offline
      R Offline
      raouls
      wrote on last edited by
      #2

      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

      R 1 Reply Last reply
      0
      • R raouls

        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

        R Offline
        R Offline
        rgoyal
        wrote on last edited by
        #3

        Thanks raoul Ranjan Goyal

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups