Flow Control Conditional statements are used to perform different actions    based on different conditions.   In JavaScr...
If Statement Use this too execute some code only if a specified condition is true.    Syntax       if(condition)         ...
If-else Statement Use this to execute some code only if the condition is true and another code if the  condition is false...
If-else Statement Example:         <script type=“text/javascript”>        //if time is less than 10 you will get a “Good ...
JavaScript Switch Statement Conditional statement are used to perform different actions based on different conditions.  T...
JavaScript Switch Statement <script type=“text/javascript>/* you will receive a different greeting based onWhat day it is....
 javascript conditional-statements
 javascript conditional-statements
Upcoming SlideShare
Loading in...5
×

javascript conditional-statements

176

Published on

5eyt6y

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
176
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

javascript conditional-statements

  1. 1. Flow Control Conditional statements are used to perform different actions based on different conditions. In JavaScript we have the following conditional statements: If statement- use this too execute some code only if a specified condition is true. If-else- use this to execute some code only if the condition is true and another code if the condition is false. Switch statement-use this statement to select one of many blocks of code to be executed.
  2. 2. If Statement Use this too execute some code only if a specified condition is true. Syntax if(condition) { code to be executed if condition is true } Example: <script type=“text/javascript”> //Write a “good morning” greeting if //the time is less than 10 var d=new Date(); var time=d.getHours(); if(time<10) { document.write(“<b>Good morning</b>”); } </script>
  3. 3. If-else Statement Use this to execute some code only if the condition is true and another code if the condition is false. Syntax if(condition) { code to be executed if condition is true. } else { code to be executed if condition is not true. }
  4. 4. If-else Statement Example: <script type=“text/javascript”> //if time is less than 10 you will get a “Good morning” greeting. //otherwise you will get a “Good day” greeting. var d=new Date(); var time=d.get.Hours(); if(time<10) { document.write(“Good morning!”); } else { document.write(“Good day!”); } </script>
  5. 5. JavaScript Switch Statement Conditional statement are used to perform different actions based on different conditions. The JavaScript Switch Statement Use the switch statement to select one of many blocks of code to be executed. Syntax- switch(n) { case 1: execute code block 1 break; case 1: execute code block 1 break; default; code to be executed if n is different from case1 and case 2 }
  6. 6. JavaScript Switch Statement <script type=“text/javascript>/* you will receive a different greeting based onWhat day it is. Note that Sunday=0,Monday=1,Tuesday=2 etc. */Var d=new Date();theDay=d.getDay();Switch(theDay){Case 5: document.write(“Finally Friday”); break;Case 6: document.write(“Super Saturday”); break;Case 0: document.write(“Sleepy Sunday”); break;default; document.write(“I m looking forward for this weekend!”);}</script>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×