JavaScript Methods

Discussion in 'OT Technology' started by doggfather, Apr 7, 2006.

  1. doggfather

    doggfather New Member

    Joined:
    Aug 6, 2005
    Messages:
    224
    Likes Received:
    0
    <script>
    var a = "";
    var b = "";
    function yes(a,b)
    {document.write(a,b);}
    yes("cool","red");
    </script>
    <body onload="javascript:yes()">
    </body>

    why won't it output coolred, it outputs undefinedundefined
     
  2. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,326
    Likes Received:
    566
    I'm not positive because I don't work in javascript very much, but I'm pretty sure you need to give arguments when you call the function. You're telling it to print nothing and nothing when you call yes(). It's expecting two arguments and gets none.
     
  3. Javi

    Javi New Member

    Joined:
    Sep 13, 2004
    Messages:
    37,785
    Likes Received:
    0
    Location:
    Houston, TX
    Code:
    <script>
    function yes(){
    var yes;
    var a = "cool";
    var b = "red";
    document.write(a,b);
    }
    </script>
    <body onload="javascript:yes();">
    
    </body>
    You set the variables to nothing. Which brings it as undefined. And you don't need the (yes("cool","red");) - it's like you're calling another function within the function - could create an infinite loop.
     

Share This Page