SlideShare ist ein Scribd-Unternehmen logo
1 von 13
JavaScript if...else Statements
REVIEW
<html>
<body>
<script>
var x= prompt("Who created the JavaScript? "," ");
var y= "Brendan Eich", n= "brendan eich", m=
  "Brendan"
var z= (x==y||x==n||x==m)?"Correct": "Wrong";
alert(""+z+"");
document.write("Correct Answer: "+y+"");
</script>
Identify if correct or error source code
If error ,find code/s or missing codes that will cause error.

7. var x= prompt(What is kbps stand for? “ ,””);

8. Var y= “kilobytes per seconds”

9. var z= (x==y) Correct: Wrong ;

10. Confirm(Are you sure);

11. msdocument.wrirte(The correct answer is “+z+”);

12. var x= parsefloatprompt(What number is less than 10? “,”)
JAVASCRIPT: CONDITIONAL STATEMENTS
• While writing a program, there may be a situation when
  you need to adopt one path out of the given two paths.
  So you need to make use of conditional statements that
  allow your program to make correct decisions and
  perform right actions.            Reference: Tutorial Points.com

• Sometimes when you write code, you want to perform
  different actions for different decisions. You can use
  conditional statements in your code to do this.
  Conditional statements are the set of commands used
  to perform different actions based on different
  conditions. JavaScript supports two conditional
  statements: if...else and switch. Both perform in saw
  way the same task.              Reference:WebCheatSheet.com
JavaScript supports conditional statements
    which are used to perform different actions
    based on different conditions. Here we will
    explain if..else statement.
JavaScript supports following forms
    of if..else statement:
if statement
if...else statement
if...else if... statement.
if statement:
The if statement is the fundamental control statement
  that allows JavaScript to make decisions and execute
  statements conditionally.

Syntax:
if (expression)
Statement(s) to be executed if expression is true
 }


Here JavaScript expression is evaluated. If the resulting value
is true, given statement(s) are executed.
If expression is false then no statement would be not executed.
Most of the times you will use comparison operators while
making decisions.
Example:
<html>
<body>
<script >
var x=prompt(“HTML stands for?”,””);
var y= “Hypertext Mark Up Language”
if(x==y)
alert(“Correct");
If(x!=y)
alert(“Wrong”);
</script>
</body>
</html>
if...else statement:
The if...else statement is the next form of control statement that
    allows JavaScript to execute statements in more controlled way.
Syntax:
if (expression)
{
 Statement(s) to be executed if expression is true
 }
else
{
 Statement(s) to be executed if expression is false
}


Here JavaScript expression is evaluated. If the resulting value
is true, given statement(s) in the if block, are executed.
If expression is false then given statement(s) in the else block, are
executed.
EXAMPLE
<html>
<body>
<script>
var x= parseFloat(prompt("Kilobytes is consist of how many bytes? ","
    "));
var y= "1000"
if(x==y)
{
    alert("Yes, Kilobytes is equal to "+x+" bytes");
}
else
{
     alert("No, Kilobytes is not equal to "+x+" bytes");
}
</script>
</body>
</html>
if...else if... statement:
The if...else if... statement is the one level
  advance form of control statement that
  allows JavaScript to make correct decision
  out of several conditions.

There is nothing special about this code. It is just a
  series of if statements, where each if is part of
  the else clause of the previous statement.
  Statement(s) are executed based on the true
  condition, if non of the condition is true
  then else block is executed
Syntax:
if (expression 1)
{
Statement(s) to be executed if expression 1 is true
}
else if (expression 2)
{
 Statement(s) to be executed if expression 2 is true
}
else if (expression 3)
{
Statement(s) to be executed if expression 3 is true
}
else
{
Statement(s) to be executed if no expression is true
}
<script>
var x= parseFloat(prompt("Enter age? "," "));
var y= 18
if(x>y)
{
    alert("Yes, You are qualified to create your account");
}
else if(x<y)
{
     alert("No, You are not qualified to create your account");
}
else if(x==y)
{
     alert("Sorry, consent with your parents is needed")
}
</script>
EXERCISES/COMPUQUIZ
Write a JavaScript source code using if…else
  conditional statements.
var year= Enter your birth year
Expression and statements

1970-1975 Your age is between 38-43 years old
1976-1980 Your age is between 33-37 years old
1981-1985 Your age is between 28-32 years old
1986-2013 Your age is between 0-27 year/s old

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]
 
Vbscript
VbscriptVbscript
Vbscript
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
Intorudction into VBScript
Intorudction into VBScriptIntorudction into VBScript
Intorudction into VBScript
 
VB Script Overview
VB Script OverviewVB Script Overview
VB Script Overview
 
Vbscript
VbscriptVbscript
Vbscript
 
Qtp - Introduction to fundamentals of vbscript
Qtp - Introduction to fundamentals of vbscriptQtp - Introduction to fundamentals of vbscript
Qtp - Introduction to fundamentals of vbscript
 
7400354 vbscript-in-qtp
7400354 vbscript-in-qtp7400354 vbscript-in-qtp
7400354 vbscript-in-qtp
 
Vb script
Vb scriptVb script
Vb script
 
Janakiram web
Janakiram webJanakiram web
Janakiram web
 
CSIS 138 Javascript Class1
CSIS 138 Javascript Class1CSIS 138 Javascript Class1
CSIS 138 Javascript Class1
 
Loops in java script
Loops in java scriptLoops in java script
Loops in java script
 
CSIS 138 JavaScript Class3
CSIS 138 JavaScript Class3CSIS 138 JavaScript Class3
CSIS 138 JavaScript Class3
 
JavaScript
JavaScriptJavaScript
JavaScript
 
CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2CSIS 138 JavaScript Class2
CSIS 138 JavaScript Class2
 
Learn VbScript -String Functions
Learn VbScript -String FunctionsLearn VbScript -String Functions
Learn VbScript -String Functions
 
Understanding solid principles
Understanding solid principlesUnderstanding solid principles
Understanding solid principles
 
Vbscript
VbscriptVbscript
Vbscript
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 

Ähnlich wie Javascript conditional statements 1

Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
Javascript comparison and logical operators
Javascript comparison and logical operatorsJavascript comparison and logical operators
Javascript comparison and logical operatorsJesus Obenita Jr.
 
Web designing unit 4
Web designing unit 4Web designing unit 4
Web designing unit 4SURBHI SAROHA
 
If conditions
If conditionsIf conditions
If conditionsMax Friel
 
05. Conditional Statements
05. Conditional Statements05. Conditional Statements
05. Conditional StatementsIntro C# Book
 
Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control StructuresPRN USM
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentalsRajiv Gupta
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript TutorialBui Kiet
 
Ch3- Java Script.pdf
Ch3- Java Script.pdfCh3- Java Script.pdf
Ch3- Java Script.pdfHASENSEID
 
Javascript conditional statements 2
Javascript conditional statements 2Javascript conditional statements 2
Javascript conditional statements 2Jesus Obenita Jr.
 
Chapter 8 - Conditional Statement
Chapter 8 - Conditional StatementChapter 8 - Conditional Statement
Chapter 8 - Conditional StatementDeepak Singh
 
An Introduction to JavaScript
An Introduction to JavaScriptAn Introduction to JavaScript
An Introduction to JavaScripttonyh1
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 

Ähnlich wie Javascript conditional statements 1 (20)

Java scripts
Java scriptsJava scripts
Java scripts
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Javascript comparison and logical operators
Javascript comparison and logical operatorsJavascript comparison and logical operators
Javascript comparison and logical operators
 
Web designing unit 4
Web designing unit 4Web designing unit 4
Web designing unit 4
 
If conditions
If conditionsIf conditions
If conditions
 
05. Conditional Statements
05. Conditional Statements05. Conditional Statements
05. Conditional Statements
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control Structures
 
1. java script language fundamentals
1. java script language fundamentals1. java script language fundamentals
1. java script language fundamentals
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
Ch3- Java Script.pdf
Ch3- Java Script.pdfCh3- Java Script.pdf
Ch3- Java Script.pdf
 
Javascript conditional statements 2
Javascript conditional statements 2Javascript conditional statements 2
Javascript conditional statements 2
 
Chapter 8 - Conditional Statement
Chapter 8 - Conditional StatementChapter 8 - Conditional Statement
Chapter 8 - Conditional Statement
 
M C6java5
M C6java5M C6java5
M C6java5
 
An Introduction to JavaScript
An Introduction to JavaScriptAn Introduction to JavaScript
An Introduction to JavaScript
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 

Mehr von Jesus Obenita Jr.

Mehr von Jesus Obenita Jr. (20)

Organization and management 3 a Evolution of Management Theory
Organization and management 3 a Evolution of Management TheoryOrganization and management 3 a Evolution of Management Theory
Organization and management 3 a Evolution of Management Theory
 
Organization and management 2 Management Function
Organization and management 2 Management FunctionOrganization and management 2 Management Function
Organization and management 2 Management Function
 
Organization and management 1
Organization and management 1Organization and management 1
Organization and management 1
 
Designing web page marquee and img tag
Designing web page  marquee and img tagDesigning web page  marquee and img tag
Designing web page marquee and img tag
 
Ms excel 2013 formatting worksheets
Ms excel 2013 formatting worksheetsMs excel 2013 formatting worksheets
Ms excel 2013 formatting worksheets
 
Ms excel 2013 data management
Ms excel 2013 data managementMs excel 2013 data management
Ms excel 2013 data management
 
Microsoft Excel introduction
Microsoft Excel introductionMicrosoft Excel introduction
Microsoft Excel introduction
 
Word 2013 working with pictures
Word 2013 working with picturesWord 2013 working with pictures
Word 2013 working with pictures
 
Word 2013 Formatting Page
Word 2013 Formatting PageWord 2013 Formatting Page
Word 2013 Formatting Page
 
Word 2013 8
Word 2013 8Word 2013 8
Word 2013 8
 
Ms word 2013 7
Ms word 2013 7Ms word 2013 7
Ms word 2013 7
 
Ms word 2013 6
Ms word 2013 6Ms word 2013 6
Ms word 2013 6
 
Ms word 2013 4
Ms word 2013 4Ms word 2013 4
Ms word 2013 4
 
Ms word 2013 2
Ms word 2013 2Ms word 2013 2
Ms word 2013 2
 
Ms word 2013
Ms word 2013Ms word 2013
Ms word 2013
 
Parts of the ms word 2013 screen and
Parts of the ms word 2013 screen andParts of the ms word 2013 screen and
Parts of the ms word 2013 screen and
 
Word processor
Word processorWord processor
Word processor
 
Session 2 test construction.mt's
Session 2   test construction.mt'sSession 2   test construction.mt's
Session 2 test construction.mt's
 
Cooking ingredients
Cooking ingredientsCooking ingredients
Cooking ingredients
 
Color theory
Color theoryColor theory
Color theory
 

Kürzlich hochgeladen

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 .pdfchloefrazer622
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
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 ImpactPECB
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 

Kürzlich hochgeladen (20)

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
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
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"
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 

Javascript conditional statements 1

  • 2. REVIEW <html> <body> <script> var x= prompt("Who created the JavaScript? "," "); var y= "Brendan Eich", n= "brendan eich", m= "Brendan" var z= (x==y||x==n||x==m)?"Correct": "Wrong"; alert(""+z+""); document.write("Correct Answer: "+y+""); </script>
  • 3. Identify if correct or error source code If error ,find code/s or missing codes that will cause error. 7. var x= prompt(What is kbps stand for? “ ,””); 8. Var y= “kilobytes per seconds” 9. var z= (x==y) Correct: Wrong ; 10. Confirm(Are you sure); 11. msdocument.wrirte(The correct answer is “+z+”); 12. var x= parsefloatprompt(What number is less than 10? “,”)
  • 4. JAVASCRIPT: CONDITIONAL STATEMENTS • While writing a program, there may be a situation when you need to adopt one path out of the given two paths. So you need to make use of conditional statements that allow your program to make correct decisions and perform right actions. Reference: Tutorial Points.com • Sometimes when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this. Conditional statements are the set of commands used to perform different actions based on different conditions. JavaScript supports two conditional statements: if...else and switch. Both perform in saw way the same task. Reference:WebCheatSheet.com
  • 5. JavaScript supports conditional statements which are used to perform different actions based on different conditions. Here we will explain if..else statement. JavaScript supports following forms of if..else statement: if statement if...else statement if...else if... statement.
  • 6. if statement: The if statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally. Syntax: if (expression) Statement(s) to be executed if expression is true } Here JavaScript expression is evaluated. If the resulting value is true, given statement(s) are executed. If expression is false then no statement would be not executed. Most of the times you will use comparison operators while making decisions.
  • 7. Example: <html> <body> <script > var x=prompt(“HTML stands for?”,””); var y= “Hypertext Mark Up Language” if(x==y) alert(“Correct"); If(x!=y) alert(“Wrong”); </script> </body> </html>
  • 8. if...else statement: The if...else statement is the next form of control statement that allows JavaScript to execute statements in more controlled way. Syntax: if (expression) { Statement(s) to be executed if expression is true } else { Statement(s) to be executed if expression is false } Here JavaScript expression is evaluated. If the resulting value is true, given statement(s) in the if block, are executed. If expression is false then given statement(s) in the else block, are executed.
  • 9. EXAMPLE <html> <body> <script> var x= parseFloat(prompt("Kilobytes is consist of how many bytes? "," ")); var y= "1000" if(x==y) { alert("Yes, Kilobytes is equal to "+x+" bytes"); } else { alert("No, Kilobytes is not equal to "+x+" bytes"); } </script> </body> </html>
  • 10. if...else if... statement: The if...else if... statement is the one level advance form of control statement that allows JavaScript to make correct decision out of several conditions. There is nothing special about this code. It is just a series of if statements, where each if is part of the else clause of the previous statement. Statement(s) are executed based on the true condition, if non of the condition is true then else block is executed
  • 11. Syntax: if (expression 1) { Statement(s) to be executed if expression 1 is true } else if (expression 2) { Statement(s) to be executed if expression 2 is true } else if (expression 3) { Statement(s) to be executed if expression 3 is true } else { Statement(s) to be executed if no expression is true }
  • 12. <script> var x= parseFloat(prompt("Enter age? "," ")); var y= 18 if(x>y) { alert("Yes, You are qualified to create your account"); } else if(x<y) { alert("No, You are not qualified to create your account"); } else if(x==y) { alert("Sorry, consent with your parents is needed") } </script>
  • 13. EXERCISES/COMPUQUIZ Write a JavaScript source code using if…else conditional statements. var year= Enter your birth year Expression and statements 1970-1975 Your age is between 38-43 years old 1976-1980 Your age is between 33-37 years old 1981-1985 Your age is between 28-32 years old 1986-2013 Your age is between 0-27 year/s old