Working with Switch Statement

Practice Labs Module
Time
18 minutes
Difficulty
Intermediate

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

Start your free 3-day trial and become one of the 3 million Cybersecurity professionals advancing their career goals
Sign up with
OR

Already have an account? Sign In »

Overview

Introduction

Welcome to the Working with Switch Statement 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 - Working with Switch Statement

Apart from the if-else and nested if-else statements, you can implement conditions in your JavaScript code with the help of switch statements. A switch statement performs different actions based on varied conditions. You can specify the conditions using the “case” keyword. You can provide various code blocks for each condition. If none of the conditions are satisfied, you can specify a default code block that is executed at the end. The syntax of the switch statement is as follows:

switch(expression)

{

case a:

code block

break;

case b:

code block

break;

default:

code block

}

The expression provided in the parentheses along with the switch statement is compared with each case condition. If the condition is true, the respective code block is executed. Else, the default code block is executed. You can specify the default code block using the default keyword. The break keyword terminates the execution and exits the switch-case.

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 switch statement in Grade.html.

Learning Outcomes

After completing this exercise, you will be able to:

  • Use the switch statement in JavaScript
Delivered By
Comprehensive Learning

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