Jump to content


Photo

Need Some Javascript Definitions


  • Please log in to reply
1 reply to this topic

#1 activeworker

activeworker

    Member

  • Member
  • PipPip
  • 15 posts

Posted 18 April 2013 - 05:22 AM

Hi Everybody!

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


try_catch_statement:

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

<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.:)
  • 0

#2 grabenair

grabenair

    Advanced Member

  • Member
  • PipPipPipPip
  • 361 posts
  • LocationIowa

Posted 18 April 2013 - 04:22 PM

The NaN is not a number just what the developer used for easy reference. You could put anything you wanted here. He used NaN for the stament because it made sense in the code. What I mean is when you name your functions, variables or even your id's and classes just do not make something up. Name them something that goes with what you are doing. Who ever wrote this code wanted to make sure that you are inputting an integer and not a letter or something like a %,*, extra.

The var txt, the txt is the name of the variable(var). Just like the function it is just the name of the var for you can call it later.

The \n is a new line.



I am going to be like my instructor here and say with the above info that I just gave you. You should be abel to come up with the answer to your last question. But if not let me know.


The on click means when an user clicks on the button. You could use other events such as hover.

Edited by grabenair, 19 April 2013 - 08:57 AM.

  • 0
Standards will change. But your website needs to remain in serving its audience.
My Portfolio site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

★★★★★ 5 Star Rated Web Developer Course - check it out now!