✏️ 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
andconst
. - 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
andconst
used? What do they mean — and how are they different fromvar
? - 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 and9
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 ofsomeName
, so choose whether you should uselet
orconst
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 variablefavoriteNumber
should not be able to be reassigned, so choose whether you should uselet
orconst
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 uselet
orconst
to declare this variable. - Set another variable called
michaelsFavorite
equal to13
. We should be able to reassign the value ofmichaelsFavorite
, so choose whether you should uselet
orconst
to declare this variable. - Subtract your favorite number from Michael's.
- Change the value of
michaelsFavorite
to be 26 times its current value.