Exercise Weekend

Goal: In the Variables video, we learned:

  • Variables, in JavaScript, are written in lower camelcase
  • Variables are set using the var keyword
  • Variables can be used in arithmetic

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

Warm Up


  • When is var used? What does it mean?
  • How can we use a variable after we've defined it?

Code


Variables Practice

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

  • Set a variable called someName equal to your name. Put your name in quotation marks.
  • Display the value of someName in the console.
  • Change the value of someName.
  • Set a variable called favoriteNumber equal to your favorite number.
  • Calculate what your favorite number divided by 2 is.
  • Set another variable called michaelsFavorite equal to 13.
  • Change the value of michaelsFavorite to 7.
  • Subtract your favorite number from mine.
  • Change the value of my favorite number to be 26 times its current value.