Skip to content

Latest commit

 

History

History
68 lines (44 loc) · 2.88 KB

javascript-5.md

File metadata and controls

68 lines (44 loc) · 2.88 KB

JavaScript 5

Projected Time

About 90 minutes

  • 15 minutes for lesson
  • 75 minutes for Independent Practice
  • 30 minutes for Check for Understanding

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.

Objectives

Participants will be able to:

  • Know when to use a switch statement instead of an if/else statement
  • Write a switch statement using proper syntax

Specific Things To Teach

  • when to use a switch statement
  • switch syntax

Lesson

JavaScript 5 (Video walkthrough of lesson slides)

  • Please watch the video the first time without working along with the demonstration. Just absorb the concepts. Then, you can watch the demonstration a second time and code with the instructor if you like.

Materials

JavaScript 5 (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

Independent Practice

Techtonica staff will assign pairs.

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).

Challenges

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).

Supplemental Materials

Check for Understanding

  • Write down the syntax of a switch statement in JavaScript.
  • What will happen if break is not used in a switch statement?
  • What is the advantage of using a switch statement over an if/else statement?
  • Using a switch statement, write a program to accept a lower case letter. Create an alert with the text 'This letter is a vowel' if the letter is a vowel.

Extensions

Complete these HackerRank Challenges: