SlideShare una empresa de Scribd logo
1 de 8
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 on
What 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>
 javascript conditional-statements

Más contenido relacionado

Similar a javascript conditional-statements

Les 2 javascript w2
Les 2 javascript w2Les 2 javascript w2
Les 2 javascript w2
mvanginkel
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoft
ch samaram
 
Javascript conditional statements 1
Javascript conditional statements 1Javascript conditional statements 1
Javascript conditional statements 1
Jesus Obenita Jr.
 
Control Structure in JavaScript (1).pptx
Control Structure in JavaScript (1).pptxControl Structure in JavaScript (1).pptx
Control Structure in JavaScript (1).pptx
BansalShrivastava
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
mussawir20
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
heoff
 

Similar a javascript conditional-statements (20)

Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statements
 
Les 2 javascript w2
Les 2 javascript w2Les 2 javascript w2
Les 2 javascript w2
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Javascript sivasoft
Javascript sivasoftJavascript sivasoft
Javascript sivasoft
 
If conditions
If conditionsIf conditions
If conditions
 
Conditions In C# C-Sharp
Conditions In C# C-SharpConditions In C# C-Sharp
Conditions In C# C-Sharp
 
csc ppt 15.pptx
csc ppt 15.pptxcsc ppt 15.pptx
csc ppt 15.pptx
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
 
Javascript conditional statements 1
Javascript conditional statements 1Javascript conditional statements 1
Javascript conditional statements 1
 
Java scripts
Java scriptsJava scripts
Java scripts
 
Janakiram web
Janakiram webJanakiram web
Janakiram web
 
Bansal presentation (1).pptx
Bansal presentation (1).pptxBansal presentation (1).pptx
Bansal presentation (1).pptx
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Control Structure in JavaScript (1).pptx
Control Structure in JavaScript (1).pptxControl Structure in JavaScript (1).pptx
Control Structure in JavaScript (1).pptx
 
Php Operators N Controllers
Php Operators N ControllersPhp Operators N Controllers
Php Operators N Controllers
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
 

Último

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Último (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

javascript conditional-statements

  • 1.
  • 2. 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.
  • 3. 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>
  • 4. 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. }
  • 5. 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>
  • 6. 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 }
  • 7. JavaScript Switch Statement <script type=“text/javascript> /* you will receive a different greeting based on What 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>