SlideShare a Scribd company logo
Conditional Constructs
if
if-else
if-elseif-else
Conditional Constructs
• Different situations  Different solutions
• Complex problem  Multiple possible
solutions
Problem with problems
• Finding the best fit solution for each problem
• Check different permutations and
combinations
IF
• If a particular condition is true -> perform a
specific action
• Eg:
– if (fruit == "apple")
fruit_color = "Red";
If-else
• If a particular condition is true -> perform a
specific action otherwise perform next action
• Eg:
– if(fruit == "apple")
fruit_color = "Red";
else
fruit_color = "Orange";
If-elseif-else
• If a particular condition is true -> perform a specific
action
• Otherwise check another condition, if true  perform
that specific action
• If none of above conditions is true  perform a
specific action
• Eg:
if(fruit=="red_apple")
fruit_color = "red";
elseif (fruit=="green_apple")
fruit_color="green";
else
fruit_color="orange";
Using Operators
• Check a specific condition
• Analyse the problem
• Find the best fit solution by checking multiple
conditions simulaneously
• Form relationship between different
conditions to be analysed
• Do arithmetic calculations
Operators
X = 10
Operand
Operator
Operand
ASSIGNMENT OPERATOR
=
Assignment Operator
• =
• Assign a value to a variable/constant/array
• Value on the RHS is assigned to the storage on
LHS
• Eg:
apples_bunch = 12;
PI = 3.14;
fruit = "apple";
RELATIONAL OPERATOR
>,<,>=,<=,==,!=
Relational Operator
• Form relationship between two conditions
• Compare the values of parameters
Relational
• To make a comparison while checking a
condition, use relational operators.
Operator Functionality Let’s consider x=5;
y=10;
> More Than x>y; False
< Less Than x<y; True
>= More Than or Equal
To
x>=y; False
<= Less Than or Equal
To
x<=y; True
== Equal to x==y; False
!= Not Equal to x!=y; True
IF
• If a particular condition is true -> perform a
specific action
• Eg:
if (fruit == 'apple')
fruit_color = 'Red';
LOGICAL OPERATOR
&&, ||, !
Logical Operator
• Form relationship between multiple
conditions
• Also known as combinational operator
– Combines different conditions together to find
solution
– AND- &&
– OR- ||
– NOT- !
Logical
• To combine two or more situations of
conditional checking use, logical operators.
Operator Functionality Condition
Example
&& Both the sides of
operator should
result true
x<y && y!=x True
x<y && y==x False
|| Either side of
operator should
result true
x<y || y!=x True
x<y || y!=x True
! Inverse the result x!<y
False
If-else
• Checking multiple conditions and parameter
values.
• Eg:
if(fruit == "apple" && fruit_color == "red")
fruit = "Red Apple";
else
fruit = 'Orange';
If-elseif-else
• Checking multiple conditions
• Eg:
if(fruit=="apple" && fruit_color == "red")
fruit = "Red Apple";
elseif (fruit=="apple" && fruit_color == "green")
fruit = "Green Apple";
else
fruit = "Orange";
ARITHMETIC OPERATOR
+,-,*,/,%
Arithmetic
• To compute arithmetic value we use
Arithmetic Operators.
Operator Functionality Condition
Example
+ Addition x+y 15
- Subtraction x-y -5
* Multiplication x*y 50
/ Division x/y 0
% Remainder x%y 5
Arithmetic Function
• Eg:
if(fruit=="apple" && fruit_color == "red")
red_apple = red_apple+1;
elseif (fruit=="apple" && fruit_color == "green")
green_apple = green_apple+1;
else
orange = orange+1;
UNARY OPERATOR
+,-,++,--
Unary Operator
• Works with a single operand
• There is no RHS (Right hand side) to the
condition
• Performing certain operations with a
shorthand
Unary Operators
• Used with single operand
Operator Functionality Condition
Example
+ Positive Value X= +15
- Negative Value X= -5
++ Increment X++ or ++X
-- Decrement X-- or --X
! NOT !x
Conditional Constructs
and
Operators used in Javascript
https://www.codewizacademy.com
https://www.facebook.com/codewizacademy/
https://www.instagram.com/codewizacademy/

More Related Content

Similar to Conditional Constructs in Javascript (20)

chap04-conditional.ppt
chap04-conditional.pptchap04-conditional.ppt
chap04-conditional.ppt
HeshamMohamed855920
 
Ch3
Ch3Ch3
Ch3
aamirsahito
 
23CSC101T PSPP python programming - UNIT 3.pdf
23CSC101T PSPP python programming - UNIT 3.pdf23CSC101T PSPP python programming - UNIT 3.pdf
23CSC101T PSPP python programming - UNIT 3.pdf
RajeshThanikachalam
 
23CSC101T PSPP python program - UNIT 3.pdf
23CSC101T PSPP python program - UNIT 3.pdf23CSC101T PSPP python program - UNIT 3.pdf
23CSC101T PSPP python program - UNIT 3.pdf
RajeshThanikachalam
 
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
prasadmutkule1
 
Javascript comparison and logical operators
Javascript comparison and logical operatorsJavascript comparison and logical operators
Javascript comparison and logical operators
Jesus Obenita Jr.
 
Copyright © 2018 Pearson Education, Inc.C H A P T E R 3.docx
Copyright © 2018 Pearson Education, Inc.C H A P T E R  3.docxCopyright © 2018 Pearson Education, Inc.C H A P T E R  3.docx
Copyright © 2018 Pearson Education, Inc.C H A P T E R 3.docx
dickonsondorris
 
c programme
c programmec programme
c programme
MitikaAnjel
 
C sharp chap3
C sharp chap3C sharp chap3
C sharp chap3
Mukesh Tekwani
 
chap8-decisionstructuresinpython123 .ppt
chap8-decisionstructuresinpython123 .pptchap8-decisionstructuresinpython123 .ppt
chap8-decisionstructuresinpython123 .ppt
sairapathan2
 
Aae oop xp_04
Aae oop xp_04Aae oop xp_04
Aae oop xp_04
Niit Care
 
Python tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingPython tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online Training
Rahul Tandale
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c language
shhanks
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++
ANANT VYAS
 
ppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operatorsppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operators
Amrinder Sidhu
 
Operators1.pptx
Operators1.pptxOperators1.pptx
Operators1.pptx
HARSHSHARMA840
 
C++ IF STATMENT AND ITS TYPE
C++ IF STATMENT AND ITS TYPEC++ IF STATMENT AND ITS TYPE
C++ IF STATMENT AND ITS TYPE
UNIVERSITY OF ENGINEERING AND TECHNOLOGY TAXILA
 
Fekra c++ Course #2
Fekra c++ Course #2Fekra c++ Course #2
Fekra c++ Course #2
Amr Alaa El Deen
 
03_Gaddis Python_Lecture_ppt_ch03.pptx
03_Gaddis Python_Lecture_ppt_ch03.pptx03_Gaddis Python_Lecture_ppt_ch03.pptx
03_Gaddis Python_Lecture_ppt_ch03.pptx
ssuser58efc81
 
Lecture - Operators in C++ (Book: Tony Gaddis).pptx
Lecture - Operators in C++ (Book: Tony Gaddis).pptxLecture - Operators in C++ (Book: Tony Gaddis).pptx
Lecture - Operators in C++ (Book: Tony Gaddis).pptx
arshadfarhad08
 
23CSC101T PSPP python programming - UNIT 3.pdf
23CSC101T PSPP python programming - UNIT 3.pdf23CSC101T PSPP python programming - UNIT 3.pdf
23CSC101T PSPP python programming - UNIT 3.pdf
RajeshThanikachalam
 
23CSC101T PSPP python program - UNIT 3.pdf
23CSC101T PSPP python program - UNIT 3.pdf23CSC101T PSPP python program - UNIT 3.pdf
23CSC101T PSPP python program - UNIT 3.pdf
RajeshThanikachalam
 
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
prasadmutkule1
 
Javascript comparison and logical operators
Javascript comparison and logical operatorsJavascript comparison and logical operators
Javascript comparison and logical operators
Jesus Obenita Jr.
 
Copyright © 2018 Pearson Education, Inc.C H A P T E R 3.docx
Copyright © 2018 Pearson Education, Inc.C H A P T E R  3.docxCopyright © 2018 Pearson Education, Inc.C H A P T E R  3.docx
Copyright © 2018 Pearson Education, Inc.C H A P T E R 3.docx
dickonsondorris
 
chap8-decisionstructuresinpython123 .ppt
chap8-decisionstructuresinpython123 .pptchap8-decisionstructuresinpython123 .ppt
chap8-decisionstructuresinpython123 .ppt
sairapathan2
 
Aae oop xp_04
Aae oop xp_04Aae oop xp_04
Aae oop xp_04
Niit Care
 
Python tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online TrainingPython tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online Training
Rahul Tandale
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c language
shhanks
 
OPERATORS OF C++
OPERATORS OF C++OPERATORS OF C++
OPERATORS OF C++
ANANT VYAS
 
ppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operatorsppt on logical/arthimatical/conditional operators
ppt on logical/arthimatical/conditional operators
Amrinder Sidhu
 
03_Gaddis Python_Lecture_ppt_ch03.pptx
03_Gaddis Python_Lecture_ppt_ch03.pptx03_Gaddis Python_Lecture_ppt_ch03.pptx
03_Gaddis Python_Lecture_ppt_ch03.pptx
ssuser58efc81
 
Lecture - Operators in C++ (Book: Tony Gaddis).pptx
Lecture - Operators in C++ (Book: Tony Gaddis).pptxLecture - Operators in C++ (Book: Tony Gaddis).pptx
Lecture - Operators in C++ (Book: Tony Gaddis).pptx
arshadfarhad08
 

More from Codewizacademy (20)

Implementing OODA Loop in online teaching
Implementing OODA Loop in online teachingImplementing OODA Loop in online teaching
Implementing OODA Loop in online teaching
Codewizacademy
 
Tie up loose ends
Tie up loose endsTie up loose ends
Tie up loose ends
Codewizacademy
 
Reflect
ReflectReflect
Reflect
Codewizacademy
 
Review
ReviewReview
Review
Codewizacademy
 
Revise
ReviseRevise
Revise
Codewizacademy
 
Organizing content of course
Organizing content of courseOrganizing content of course
Organizing content of course
Codewizacademy
 
Rules and policies for course
Rules and policies for courseRules and policies for course
Rules and policies for course
Codewizacademy
 
Content Creation
Content CreationContent Creation
Content Creation
Codewizacademy
 
Taxonomies
TaxonomiesTaxonomies
Taxonomies
Codewizacademy
 
Course outline
Course outlineCourse outline
Course outline
Codewizacademy
 
Course development
Course developmentCourse development
Course development
Codewizacademy
 
Looping
LoopingLooping
Looping
Codewizacademy
 
Displaying message on web page in Javascript
Displaying message on web page in JavascriptDisplaying message on web page in Javascript
Displaying message on web page in Javascript
Codewizacademy
 
Storage in programming
Storage in programmingStorage in programming
Storage in programming
Codewizacademy
 
Cyber Security
Cyber SecurityCyber Security
Cyber Security
Codewizacademy
 
Website Security
Website SecurityWebsite Security
Website Security
Codewizacademy
 
Website Cookies
Website CookiesWebsite Cookies
Website Cookies
Codewizacademy
 
GDPR- General Data Protection Regulation
GDPR- General Data Protection RegulationGDPR- General Data Protection Regulation
GDPR- General Data Protection Regulation
Codewizacademy
 
CSS- Cascading Style Sheet
CSS- Cascading Style SheetCSS- Cascading Style Sheet
CSS- Cascading Style Sheet
Codewizacademy
 
HTML- Hyper Text Markup Language
HTML- Hyper Text Markup LanguageHTML- Hyper Text Markup Language
HTML- Hyper Text Markup Language
Codewizacademy
 
Ad

Recently uploaded (20)

IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive LearningSustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation SamplerLDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdfGEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Himalayan Group of Professional Institutions (HGPI)
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptxWhat is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo SlidesOverview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptxROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke WarnerPublishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdfABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptxjune 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive LearningSustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation SamplerLDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdfFEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdfGEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptxWhat is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo SlidesOverview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptxROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
What are the benefits that dance brings?
What are the benefits that dance brings?What are the benefits that dance brings?
What are the benefits that dance brings?
memi27
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke WarnerPublishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdfABCs of Bookkeeping for Nonprofits TechSoup.pdf
ABCs of Bookkeeping for Nonprofits TechSoup.pdf
TechSoup
 
Ad

Conditional Constructs in Javascript

  • 2. Conditional Constructs • Different situations  Different solutions • Complex problem  Multiple possible solutions
  • 3. Problem with problems • Finding the best fit solution for each problem • Check different permutations and combinations
  • 4. IF • If a particular condition is true -> perform a specific action • Eg: – if (fruit == "apple") fruit_color = "Red";
  • 5. If-else • If a particular condition is true -> perform a specific action otherwise perform next action • Eg: – if(fruit == "apple") fruit_color = "Red"; else fruit_color = "Orange";
  • 6. If-elseif-else • If a particular condition is true -> perform a specific action • Otherwise check another condition, if true  perform that specific action • If none of above conditions is true  perform a specific action • Eg: if(fruit=="red_apple") fruit_color = "red"; elseif (fruit=="green_apple") fruit_color="green"; else fruit_color="orange";
  • 7. Using Operators • Check a specific condition • Analyse the problem • Find the best fit solution by checking multiple conditions simulaneously • Form relationship between different conditions to be analysed • Do arithmetic calculations
  • 10. Assignment Operator • = • Assign a value to a variable/constant/array • Value on the RHS is assigned to the storage on LHS • Eg: apples_bunch = 12; PI = 3.14; fruit = "apple";
  • 12. Relational Operator • Form relationship between two conditions • Compare the values of parameters
  • 13. Relational • To make a comparison while checking a condition, use relational operators. Operator Functionality Let’s consider x=5; y=10; > More Than x>y; False < Less Than x<y; True >= More Than or Equal To x>=y; False <= Less Than or Equal To x<=y; True == Equal to x==y; False != Not Equal to x!=y; True
  • 14. IF • If a particular condition is true -> perform a specific action • Eg: if (fruit == 'apple') fruit_color = 'Red';
  • 16. Logical Operator • Form relationship between multiple conditions • Also known as combinational operator – Combines different conditions together to find solution – AND- && – OR- || – NOT- !
  • 17. Logical • To combine two or more situations of conditional checking use, logical operators. Operator Functionality Condition Example && Both the sides of operator should result true x<y && y!=x True x<y && y==x False || Either side of operator should result true x<y || y!=x True x<y || y!=x True ! Inverse the result x!<y False
  • 18. If-else • Checking multiple conditions and parameter values. • Eg: if(fruit == "apple" && fruit_color == "red") fruit = "Red Apple"; else fruit = 'Orange';
  • 19. If-elseif-else • Checking multiple conditions • Eg: if(fruit=="apple" && fruit_color == "red") fruit = "Red Apple"; elseif (fruit=="apple" && fruit_color == "green") fruit = "Green Apple"; else fruit = "Orange";
  • 21. Arithmetic • To compute arithmetic value we use Arithmetic Operators. Operator Functionality Condition Example + Addition x+y 15 - Subtraction x-y -5 * Multiplication x*y 50 / Division x/y 0 % Remainder x%y 5
  • 22. Arithmetic Function • Eg: if(fruit=="apple" && fruit_color == "red") red_apple = red_apple+1; elseif (fruit=="apple" && fruit_color == "green") green_apple = green_apple+1; else orange = orange+1;
  • 24. Unary Operator • Works with a single operand • There is no RHS (Right hand side) to the condition • Performing certain operations with a shorthand
  • 25. Unary Operators • Used with single operand Operator Functionality Condition Example + Positive Value X= +15 - Negative Value X= -5 ++ Increment X++ or ++X -- Decrement X-- or --X ! NOT !x
  • 26. Conditional Constructs and Operators used in Javascript https://www.codewizacademy.com https://www.facebook.com/codewizacademy/ https://www.instagram.com/codewizacademy/