Jump to content
Killersites Forums

Need Some Javascript Definitions


Recommended Posts

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

Link to post
Share on other sites

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
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...