Javascript: Conditional Statement
Javascript: Conditional Statement
Conditional statement
OBJECTIVE
Students will be able to understand the conditional statement.
OUTLINE
control statements
If
if-else
if- else if
IF-ELSE
IF-ELSE
The ‘if’ statement is the fundamental control statement that allows JavaScript to make
decisions and execute statements conditionally. Syntax The syntax for a basic if statement is as
follows:
Syntax
if (expression)
{ Statement(s) to be executed if expression is true }
IF EXAMPLE
output
IF-ELSE EXAMPLE
<html>
else{
<body> document.write("<b>Does not qualify
for driving</b>");
<script type="text/javascript">
}
var age = 15;
</script>
if( age > 18 ){ <p>Set the variable to different value
document.write("<b>Qualifies and then try...</p>
for driving</b>"); </body>
</html>
}
REFERENCES
Java Script & J Query by Jon Duckett, Volume 2 (2014), ISBN-13: 978-1118531648, ISBN-
10: 9781118531648.
W3Schools url: www.w3school.com
TutorialsPoint url: www.tutorialpoint.com