Put two statements inside an if block and show the result.
Acceptance criteria
- 1.#out should show grouped.
JavaScript Tutorial · JavaScript Statement & Expression
These 10 tasks go with the JavaScript Code Blocks 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 code blocks are used to group multiple statements together.” .
1.Group statements in a blockexercise · easy · 10 min
Put two statements inside an if block and show the result.
Passes when: #out should show grouped.
2.Use a standalone blockexercise · easy · 10 min · practice plan
A bare { } block is valid — use one and show "blocked".
Passes when: #out should show blocked.
3.Scope a variable to a blockexercise · easy · 10 min · practice plan
Declare inside a block and read it there.
Passes when: #out should show scoped.
4.Read an outer variable inside a blockexercise · easy · 10 min · practice plan
Inner blocks can read outer values.
Passes when: #out should show outer.
5.Shadow a name in a blockexercise · medium · 10 min · practice plan
An inner block can declare its own version of a name.
Passes when: #out should show inner.
6.Fix the missing bracesbug fix · easy · 8 min
Only the first line belongs to the if without braces.
Passes when: #out should show guarded.
7.Fix the variable read outside its blockbug fix · easy · 8 min · practice plan
A const declared in a block is not visible outside it.
Passes when: #out should show scoped.
8.Fix the unclosed blockbug fix · easy · 8 min · practice plan
A missing closing brace breaks the whole script.
Passes when: #out should show closed.
9.Fix the shadowed namebug fix · easy · 8 min · practice plan
The inner declaration hides the value that should be shown.
Passes when: #out should show outer.
10.Fix the block attached to nothingbug fix · easy · 8 min · practice plan
The condition is separated from its block by a semicolon.
Passes when: #out should show conditional.
Between them these tasks cover Block statements and Block scope.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.