javascript conditional-statements
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

javascript conditional-statements

on

  • 420 views

 

Statistics

Views

Total Views
420
Views on SlideShare
362
Embed Views
58

Actions

Likes
0
Downloads
2
Comments
0

3 Embeds 58

http://www.ustudy.in 38
http://localhost 16
http://ustudy.in 4

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

javascript conditional-statements Presentation 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>