In programming, we often need to give computer the intelligence to take decisions in different situtations. If a certain condition is met, perform an action, if another condition is met perform the another specified operation. These are referred to as conditional statements-example below will clarify it.
Example
When customers come to our fashion website, they have to enter name and select Gender. Based on the Gender information receive, through programming we give computer the intelligence to decide whether to Greet the Visitor as Madam or Sir.
Condition 1- Gender = Male
Condition 2- Gender = Female
How we program it into the computer
We tell the computer the list of Conditions and the actions to perform if a condition is met.
IF Gender is male , greet the visitor as 'Dear Sir. Welcome to the site'
IF Gender is female, greet the visitor as 'Dear Madam. Welcome to the site'
The thing is we cannot have a person sitting with a computer and everytime someone visits the site, the operator types in the Dear sir greeting or Dear madam greeting Programming lets us automate such operations. Computer decides and computer types the greeting.
Conditional statements used in JavaScript
We will be covering the following conditional statements used in JavaScript
If statement
If else statement
If else ... If else statements
Switch statement
We will look at each one of these in detail and with practical examples in the coming lessons.
Conditional Statements table. Differences
Example
When customers come to our fashion website, they have to enter name and select Gender. Based on the Gender information receive, through programming we give computer the intelligence to decide whether to Greet the Visitor as Madam or Sir.
Condition 1- Gender = Male
Condition 2- Gender = Female
How we program it into the computer
We tell the computer the list of Conditions and the actions to perform if a condition is met.
IF Gender is male , greet the visitor as 'Dear Sir. Welcome to the site'
IF Gender is female, greet the visitor as 'Dear Madam. Welcome to the site'
The thing is we cannot have a person sitting with a computer and everytime someone visits the site, the operator types in the Dear sir greeting or Dear madam greeting Programming lets us automate such operations. Computer decides and computer types the greeting.
Conditional statements used in JavaScript
We will be covering the following conditional statements used in JavaScript
If statement
If else statement
If else ... If else statements
Switch statement
We will look at each one of these in detail and with practical examples in the coming lessons.
Conditional Statements table. Differences
Aucun commentaire:
Enregistrer un commentaire