SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Threaded View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Location
    Pabna, Bangladesh
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need some JavaScript definitions

    Hi Everybody!

    Good day
    I like to know some JavaScript definitions are following:


    try_catch_statement:

    Code HTML4Strict:
    <html>
    <head>
    <script type="text/javascript">
    var txt="";
    function message()
    {
    try
      {
      adddlert("Welcome guest!");
      }
    catch(err)
      {
      txt="There was an error on this page.\n\n";
      txt+="Error description: " + err.description + "\n\n";
      txt+="Click OK to continue.\n\n";
      alert(txt);
      }
    }
    </script>
    </head>
     
    <body>
    <input type="button" value="View message" onClick="message()" />
    </body>
     
    </html>

    Please see the codes above and give me the following answer:

    # What is “txt”? Why I should use this?
    # What is “There was an error on this page.\n\n”? What is .\n\n?
    # What is “txt+="Error description: " + err.description + "\n\n";” here? I mean
    txt+,
    Error description:,
    err.description and
    "\n\n"?
    # What is “onClick="message()” as well?



    throw_statement:

    Code HTML4Strict:
    <html>
    <body>
    <script type="text/javascript">
    var x=prompt("Enter a number between 0 and 10:","");
    try
    { 
    if(x>10)
      {
      throw "Err1";
      }
    else if(x<0)
      {
      throw "Err2";
      }
    else if(isNaN(x))
      {
      throw "Err3";
      }
    }
    catch(er)
    {
    if(er=="Err1")
      {
      alert("Error! The value is too high");
      }
    if(er=="Err2")
      {
      alert("Error! The value is too low");
      }
    if(er=="Err3")
      {
      alert("Error! The value is not a number");
      }
    }
    </script>
    </body>
    </html>

    # What is “else if(isNaN(x))”? Why I should use it?

    No more, I am waiting for your kind response.

    Thank you.
    Last edited by TechnoBear; Apr 18, 2013 at 03:35. Reason: Code tags added


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •