Declare a variable named score, set it to 42, and show it.
Acceptance criteria
- 1.Declare score with let.
- 2.#out should show 42.
JavaScript Tutorial · JavaScript Basics
These 10 tasks go with the JavaScript Variables chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “JavaScript variables are used to store data values.” .
1.Declare a variable with letexercise · easy · 10 min
Declare a variable named score, set it to 42, and show it.
Passes when: Declare score with let; #out should show 42.
2.Use const for a fixed valueexercise · easy · 10 min · practice plan
Store the site name in a constant and display it.
Passes when: Use const for siteName.
3.Reassign a let variableexercise · easy · 10 min · practice plan
Start count at 5, reassign it to 9, then show the final value.
Passes when: Reassign count before showing it.
4.Combine two variablesexercise · easy · 10 min · practice plan
Join a first and last name into one full name.
Passes when: Show the two names separated by a space.
5.Swap two variablesexercise · medium · 10 min · practice plan
Given a = 1 and b = 2, swap them and show them as "2,1".
Passes when: After swapping, show a then b.
6.Fix the misspelled variablebug fix · easy · 8 min
The value never appears because the variable name is wrong.
Passes when: #out should show 42.
7.Fix the reassigned constantbug fix · easy · 8 min · practice plan
This code throws because a const is being reassigned.
Passes when: #out should show 9.
8.Fix the variable used too earlybug fix · easy · 8 min · practice plan
The variable is read before it is declared.
Passes when: #out should show hello.
9.Fix the missing quotesbug fix · easy · 8 min · practice plan
A text value was written without quotes, so it is treated as a variable.
Passes when: #out should show welcome.
10.Fix the wrong concatenationbug fix · easy · 8 min · practice plan
The full name is missing the space between the two parts.
Passes when: #out should show Grace Hopper.
Between them these tasks cover Declaring variables, let vs const and Assignment.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.