Values, variables, and types

Store strings, numbers, booleans, and missing values with const and let.

Difficulty
beginner
Time
40 minutes
Last verified
9/21/2026

What you will build

Store strings, numbers, booleans, and missing values with const and let.

Understand the idea first

Store strings, numbers, booleans, and missing values with const and let.

Build it step by step

const courseName = 'HTML 基础';
let completedLessons = 3;
const lessonCount = 12;
const isFinished = completedLessons === lessonCount;
console.log(typeof courseName, isFinished);
  1. Open the project from the previous lesson and record its current result.
  2. Type and run the example, then complete this task: Before creating your course state, test completion values 0, 12, and 13.
  3. Change at least one input, predict the result, and verify it.
  4. Create and repair this lesson's typical failure: Form input may be a string; convert with Number() and check for NaN.

Read the important lines

  • Store strings, numbers, booleans, and missing values with const and let.
  • Read the code as input, processing, and output; point to each part.
  • A first successful run is not enough; verify a different input and an edge case.

Common mistakes and what to check

SymptomWhat to check
The result differs from the predictionForm input may be a string; convert with Number() and check for NaN.
Nothing changes after refreshSave the file, verify the script path, and read the first relevant Console error.

Practice without copying

Before creating your course state, test completion values 0, 12, and 13.

Check the answer after you try

Rebuild it without copying and explain each decision. Key check: Form input may be a string; convert with Number() and check for NaN.

Completion check

  • I produced the required visible result
  • I can explain the input, processing, and output
  • I tested normal, edge, and failure cases

Your privacy choices

Necessary storage is always on. Optional analytics and support services load only after consent.