MyPrefix
Content Interaction Strategist
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
In this tutorial, we are going to learn about If, Else, Else If Statement using JavaScript. These all statement execute with a condition. With the use If, Else, and Else If, you can make your program knowledgeable.
If Statement - JavaScript
This is If Statement. It will execute if the condition is True.
This is the Output:
If... Else Statement - JavaScript
The example above will execute only if the condition is true. If.. Else statement it will execute another statement if the condition is false.
This is the Output:
If... Else If... Else Statement - JavaScript
You can use this statement if you want multiple conditions.
This is the Output:
Hope that this simple tutorial that I created may help you to your future projects. Also, for the beginners who want to learn basic of coding in JavaScript.
Related Code: PHP If…Else Statements
Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.
Download
If Statement - JavaScript
This is If Statement. It will execute if the condition is True.
- <
script>
- var
age =
16
;
- if
(
age <
18
)
{
- {
- alert (
" You are a minor."
)
;
- }
- }
- </
script>
This is the Output:

If... Else Statement - JavaScript
The example above will execute only if the condition is true. If.. Else statement it will execute another statement if the condition is false.
- <
script>
- var
age =
0
;
- if
(
age <
18
)
{
- if
(
age >
0
)
- {
- alert (
" You are a minor."
)
;
- }
else
{
- alert (
"Input Correct Details. Try Again."
)
;
- }
- }
- </
script>
This is the Output:

If... Else If... Else Statement - JavaScript
You can use this statement if you want multiple conditions.
- <
script>
- var
age =
19
;
- if
(
age <
18
)
{
- if
(
age >
0
)
- {
- alert (
" You are a minor."
)
;
- }
else
{
- alert (
"Input Correct Details. Try Again."
)
;
- }
- }
else
if
(
age >=
18
)
- {
- alert (
"You are already an Adult."
)
- }
- </
script>
This is the Output:

Hope that this simple tutorial that I created may help you to your future projects. Also, for the beginners who want to learn basic of coding in JavaScript.
Related Code: PHP If…Else Statements
Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.
Download
You must upgrade your account or reply in the thread to view hidden text.