Your SlideShare is downloading. ×
 javascript conditional-statements
 javascript conditional-statements
 javascript conditional-statements
 javascript conditional-statements
 javascript conditional-statements
 javascript conditional-statements
 javascript conditional-statements
 javascript conditional-statements
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

javascript conditional-statements

165

Published on

5eyt6y

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
165
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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. 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. 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. 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. 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. 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>

×