Skip to main content
Version: v1.2

✏️ 1.2.0.11 Practice: Variables and Strings

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 created 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 (double or single).
  • Variables can be set equal to strings.
  • To escape characters use the backslash \ 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?
  • Can we create strings with either 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 in the DevTools console:

  • 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 another name.
  • 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 Michael's.
  • Change the value of michaelsFavorite to be 26 times its current value.