Working with If Statements

Practice Labs Module
Time
6 minutes
Difficulty
Intermediate

Welcome to the "Working with If Statements" Practice Lab. In this module, you will be provided with the instructions and devices needed to develop your hands-on skills.

Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Overview

Introduction

Welcome to the Working with If Statements Practice Lab. In this module, you will be provided with the instructions and devices needed to develop your hands-on skills.

Exam Objectives

The following exam objective is covered in this lab:

  • 3.2 Complete and debug decision statements

Lab Duration

It will take approximately 15 minutes to complete this lab.

Exercise 1 - Handling Decision Making with If Statements

Decision-making is an important aspect of any programming language. You can implement decision-making in JavaScript by using the conditional or decision-making statements such as if-else and nested if-else. Based on the conditions specified, the decision-making statements decide the flow of the program.

You can specify a condition using the if-else statement in the program. The condition can return either a true or a false value. If the value is true, a certain set of statements following the ‘if’ statement is executed. If the value is false, the set of statements following the ‘else’ statement is executed. The else statement is optional in an if-else block. You can have only one else statement for each if statement.

The syntax of if-else statement is as follows:

if

{

}

else

{

}

You can have an else if statement within an if-else statement block. The else if statement helps to include multiple check conditions. This statement is optional. You can also have multiple else if statements in an if-else block.

The syntax of else if statement is as follows:

if

{

}

else if

{

}

else

{

}

You can specify multiple conditions using nested if-else statements. You can embed a set of if-else statements within another set of if-else statements.

The syntax of nested if-else statement is as follows:

if

{

if

{

}

else

{

}

}

else

{

}

In this exercise, you will perform two tasks:

  • Task 1 - You will download the Visual Studio Code workspace (ComputeGrade) from the Intranet and open the HTML page named Grade.html in the ComputeGrade workspace.

  • Task 2 - You will write JavaScript code to use the if-else and nested if-else statements.

Learning Outcomes

After completing this exercise, you will be able to:

  • Use the if-else and nested if-else statements in JavaScript
Learning Partner
Comprehensive Learning

See the full benefits of our immersive learning experience with interactive courses and guided career paths.