• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
 javascript conditional-statements
 

javascript conditional-statements

on

  • 227 views

5eyt6y

5eyt6y

Statistics

Views

Total Views
227
Views on SlideShare
226
Embed Views
1

Actions

Likes
0
Downloads
1
Comments
0

1 Embed 1

http://localhost 1

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

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