SlideShare a Scribd company logo
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

More Related Content

PPTX
Javascript conditional statements
PPTX
JavaScript Conditional Statements
PPTX
VB Script
PDF
PPT
Javascript sivasoft
PPT
QTP VB Script Trainings
PPTX
Basic vbscript for qtp
DOC
Introduction to java script
Javascript conditional statements
JavaScript Conditional Statements
VB Script
Javascript sivasoft
QTP VB Script Trainings
Basic vbscript for qtp
Introduction to java script

What's hot (20)

PDF
Vb script tutorial for qtp[1]
PDF
Vbscript
PPTX
Introduction to java script
PPT
Intorudction into VBScript
PPT
VB Script Overview
PPTX
PPT
Qtp - Introduction to fundamentals of vbscript
PDF
7400354 vbscript-in-qtp
PPT
Vb script
DOCX
Janakiram web
PPT
CSIS 138 Javascript Class1
PPTX
Loops in java script
PPT
CSIS 138 JavaScript Class3
PPT
JavaScript
PPT
CSIS 138 JavaScript Class2
DOC
Learn VbScript -String Functions
PDF
Understanding solid principles
PPT
Vbscript
PPTX
Switch case and looping jam
DOCX
Vb script tutorial
Vb script tutorial for qtp[1]
Vbscript
Introduction to java script
Intorudction into VBScript
VB Script Overview
Qtp - Introduction to fundamentals of vbscript
7400354 vbscript-in-qtp
Vb script
Janakiram web
CSIS 138 Javascript Class1
Loops in java script
CSIS 138 JavaScript Class3
JavaScript
CSIS 138 JavaScript Class2
Learn VbScript -String Functions
Understanding solid principles
Vbscript
Switch case and looping jam
Vb script tutorial
Ad

Similar to Javascript conditional statements 1 (20)

RTF
Java scripts
PPTX
javascriptbasicsPresentationsforDevelopers
DOCX
PDF
PDF
Javascript basics
PDF
web programming javascriptconditionalstatements.pdf
PDF
Java Script 2nd lec.pdfsssssssssssssssss
PDF
Loops and conditional statements
PPTX
Javascript comparison and logical operators
PPTX
Web designing unit 4
PDF
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
PPT
If conditions
PPTX
4TH QUARTER LESSONS-CP(IF STATEMENT).pptx
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
PPTX
05. Conditional Statements
PPTX
Control Statement programming
PDF
JavaScript Notes šŸ”„.pdfssssssssssssssssssssssssssssssssssssssssss
PPTX
control-structure.pptxcontrol-structure.pptx
PPT
Selection Control Structures
PPTX
1. java script language fundamentals
Java scripts
javascriptbasicsPresentationsforDevelopers
Javascript basics
web programming javascriptconditionalstatements.pdf
Java Script 2nd lec.pdfsssssssssssssssss
Loops and conditional statements
Javascript comparison and logical operators
Web designing unit 4
OIT 116 LOOPS AND CONDITION STATEMENTS.pdf
If conditions
4TH QUARTER LESSONS-CP(IF STATEMENT).pptx
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
05. Conditional Statements
Control Statement programming
JavaScript Notes šŸ”„.pdfssssssssssssssssssssssssssssssssssssssssss
control-structure.pptxcontrol-structure.pptx
Selection Control Structures
1. java script language fundamentals
Ad

More from Jesus Obenita Jr. (20)

PPTX
Organization and management 3 a Evolution of Management Theory
PPTX
Organization and management 2 Management Function
PPTX
Organization and management 1
PPTX
Designing web page marquee and img tag
PPTX
Ms excel 2013 formatting worksheets
PPTX
Ms excel 2013 data management
PPTX
Microsoft Excel introduction
PPTX
Word 2013 working with pictures
PPTX
Word 2013 Formatting Page
PPTX
Word 2013 8
PPTX
Ms word 2013 7
PPTX
Ms word 2013 6
PPTX
Ms word 2013 4
PPTX
Ms word 2013 2
PPTX
Ms word 2013
PPTX
Parts of the ms word 2013 screen and
PPTX
Word processor
PPT
Session 2 test construction.mt's
PPTX
Cooking ingredients
PPTX
Color theory
Organization and management 3 a Evolution of Management Theory
Organization and management 2 Management Function
Organization and management 1
Designing web page marquee and img tag
Ms excel 2013 formatting worksheets
Ms excel 2013 data management
Microsoft Excel introduction
Word 2013 working with pictures
Word 2013 Formatting Page
Word 2013 8
Ms word 2013 7
Ms word 2013 6
Ms word 2013 4
Ms word 2013 2
Ms word 2013
Parts of the ms word 2013 screen and
Word processor
Session 2 test construction.mt's
Cooking ingredients
Color theory

Recently uploaded (20)

PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
01-Introduction-to-Information-Management.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Cell Structure & Organelles in detailed.
PPTX
Lesson notes of climatology university.
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
Microbial diseases, their pathogenesis and prophylaxis
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
A systematic review of self-coping strategies used by university students to ...
01-Introduction-to-Information-Management.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Cell Structure & Organelles in detailed.
Lesson notes of climatology university.
Microbial disease of the cardiovascular and lymphatic systems
VCE English Exam - Section C Student Revision Booklet
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Weekly quiz Compilation Jan -July 25.pdf
Computing-Curriculum for Schools in Ghana
Final Presentation General Medicine 03-08-2024.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Supply Chain Operations Speaking Notes -ICLT Program

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