Javascript Tutorial Part-3  

Posted by Kunal Pradhan

objective: to learn the if..else statements...

what is if...else statements?
if else statements are used as conditional statements..

for example .. if a certain condition is true ...which script to run .. and if it is false then what to do ...
these statements are very useful !!!


IF STATEMENT

it tells the script what to do when a certain condition is true ...
this is how it should be used :
if (condition){the code that should execute if the condition is true.}

e.g.
javascript:var a=prompt("insert a number between 1-1000","Enter number");if (a<750){alert("number is less then 750")}



IF ElSE STATEMENT

it tells the script what to do when a certain condition is true ... and what to do if it is false.
this is how it should be used :
if (condition){the code that should execute if the condition is true.}else{code to execute if it is false}

e.g.
javascript:var a=prompt("insert a number between 1-1000","Enter a number");if (a<750){alert("number is less then 750")}else{alert("number greater then 750")}


Prompt function we can give default value as second element

like
javascript:prompt("Enter your name","kunal");void(0)

I have given my name as default value.

Read all javascript tutorials Click here

This entry was posted on Wednesday, June 18, 2008 and is filed under , . You can leave a response and follow any responses to this entry through the Subscribe to: Post Comments (Atom) .

0 comments