Skip to content

Latest commit

 

History

History
53 lines (31 loc) · 2.48 KB

javascript-5-switch.md

File metadata and controls

53 lines (31 loc) · 2.48 KB

JavaScript 5 - Switch Statements

Week 3 Keywords and Questions

(refer to slides and MDN article)

  • What is a switch statement, when would I use one?
  • Why a switch statement over an if/else?
  • What is the syntax of a switch statement?
  • What is the “break” part of a switch statement, and what will happen if no break statement is used?

Prerequisites

Motivation

JavaScript is used on the frontend of almost every website. It's also a widely-used scripting language that be used on the backend as well. The JavaScript lessons set a solid foundation in JavaScript basics so we can use the language in more robust ways in later lessons.

Specific Things to Learn

  • when to use a switch statement
  • switch syntax

Lesson

JavaScript 5 (Video walkthrough of lesson slides)

JavaScript 5 - Switch Statements (slides)

Common Mistakes / Misconceptions

  • You need a break statement at the end of each case.

  • There is no comparison operator in a switch statement, but there is one in the if/else statement

Supplemental Materials

Additional Challenges

If you have previously completed it, refer back to the calculator activity from the JavaScript 1 lesson. Refactor your code to replace your if/else statement(s) with switch statement(s).

If you have previously completed it, refer back to the movie night activity from the JavaScript 3 lesson. Refactor your code to replace your if/else statement(s) with switch statement(s).

Complete these HackerRank Challenges: