Explain the line with a // comment, then show "documented".
Acceptance criteria
- 1.#out should show documented.
JavaScript Tutorial · JavaScript Introduction
These 10 tasks go with the JavaScript Comments 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 comments are used to write notes inside code, explain logic, and temporarily disable JavaScript during testing.” .
1.Add a line commentexercise · easy · 10 min
Explain the line with a // comment, then show "documented".
Passes when: #out should show documented.
2.Use a block commentexercise · easy · 10 min · practice plan
Add a /* */ comment above the code, then show "blocked".
Passes when: #out should show blocked.
3.Comment out a lineexercise · easy · 10 min · practice plan
Disable the wrong line with a comment so "correct" is shown.
Passes when: #out should show correct.
4.Comment at the end of a lineexercise · easy · 10 min · practice plan
Add a trailing comment after the statement.
Passes when: #out should show trailing.
5.Keep code readableexercise · medium · 10 min · practice plan
Explain a calculation with a comment and show "clear".
Passes when: #out should show clear.
6.Fix the unclosed block commentbug fix · easy · 8 min
The block comment never closes, so the real code is swallowed.
Passes when: #out should show visible.
7.Fix the commented-out codebug fix · easy · 8 min · practice plan
The working line was accidentally commented out.
Passes when: #out should show active.
8.Fix the wrong comment markerbug fix · easy · 8 min · practice plan
A hash is not a JavaScript comment.
Passes when: #out should show commented.
9.Fix the comment that hides half a linebug fix · easy · 8 min · practice plan
The comment starts too early and disables the assignment.
Passes when: #out should show restored.
10.Fix the nested block commentbug fix · easy · 8 min · practice plan
Block comments cannot nest, so this breaks.
Passes when: #out should show fixed.
Between them these tasks cover Line comments, Block comments and Commenting out code.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.