JavaScript Variables — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Variables lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Declare a variable with let
easy10 minDeclare a variable named score, set it to 42, and show it.
- Declare score with let.
- #out should show 42.
- 2
Use const for a fixed value
easy10 minStore the site name in a constant and display it.
- 3
Reassign a let variable
easy10 minStart count at 5, reassign it to 9, then show the final value.
- 4
Combine two variables
easy10 minJoin a first and last name into one full name.
- 5
Swap two variables
medium10 minGiven a = 1 and b = 2, swap them and show them as "2,1".
Find the bug(5)
- 1
Fix the misspelled variable
easy8 minThe value never appears because the variable name is wrong.
- 2
Fix the reassigned constant
easy8 minThis code throws because a const is being reassigned.
- 3
Fix the variable used too early
easy8 minThe variable is read before it is declared.
- 4
Fix the missing quotes
easy8 minA text value was written without quotes, so it is treated as a variable.
- 5
Fix the wrong concatenation
easy8 minThe full name is missing the space between the two parts.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace