Exercise Weekend

Goal: Practice creating and utilizing variables and Strings by completing the exercises listed below. Variables and Strings are both a fundamental building block of programming, so begin getting comfortable with them now!

In the Variables lesson, we learned:

  • Variables, in JavaScript, are written in lower camelCase
  • In modern JavaScript, variables are set using let and const
  • Variables can be used in arithmetic

In the Strings lesson, we learned:

  • Strings can include letters, punctuation, and numbers
  • Strings are surrounded with quotation marks
  • Variables can be set equal to strings
  • To escape characters use the \ character

Warm Up


  • When are let and const used? What do they mean - and how are they different from var?
  • How can we use a variable after we've defined it?
  • How do we declare a String?
  • Do Strings require single or double quotes?
  • What's the difference between "9" with quotes and 9 without?

Code


Variables and Strings Practice

Here are a few exercises for you to practice using variables:

  • Set a variable called someName equal to your name in a String. We should be able to reassign the value of someName, so choose whether you should use let or const to declare this variable.
  • Display the value of someName in the console.
  • Change the value of someName to your pair's name.

Switch who's driving and observing and continue with these next practice items:

  • Set a variable called favoriteNumber equal to your favorite number. The variable favoriteNumber should not be able to be reassigned, so choose whether you should use let or const to declare this variable.
  • Calculate what your favorite number divided by 2 is, and save the result in a new variable called halfOfFavNum. This variable should not be able to be reassigned, so choose whether you should use let or const to declare this variable.
  • Set another variable called michaelsFavorite equal to 13. We should be able to reassign the value of michaelsFavorite, so choose whether you should use let or const to declare this variable.
  • Subtract your favorite number from mine.
  • Change the value of michaelsFavorite to be 26 times its current value.

Lesson 10 of 65
Last updated May 23, 2022