Skip to content

Checkpoint: Study Receipt

The Course
•
25 min study

This checkpoint is a small independent task. Budget about twenty-five minutes: five to plan, fifteen to implement and check, and five to explain and change the inputs. Close earlier solutions first. A hint is a normal part of learning, but try to name the obstacle before opening it.

Your receipt has a topic, a number of sessions, a duration per session, and a completion flag. These are ordinary JavaScript values. TypeScript helps preserve their roles as you change the program.

Write down the expected message before opening the editor. Decide which variables will change and use let only for those. You may infer obvious local types. For this checkpoint, practice explicit annotations on at least two values too.

After the first successful run, deliberately introduce a type mismatch. Read the compiler message out loud, then restore the program. A passing check and a correct output answer different questions; record evidence for both.

The tiny demonstration below is a reminder, not the completed receipt. Your task uses different data and a full sentence.

Predict, check, then run

Before running, write down the output and explain which information the checker knows. Click Check types first, then Check & run.

Predict, then runTypeScript
const topic: string = "Arrays";
const minutes = 15;

console.log(`${topic}: ${minutes}`);

Enable JavaScript to edit and type-check this example.

Check your prediction
Text
Arrays: 15

Acceptance cases before you code

Before you write the receipt, write down what each change below should print. Then try each one in your finished program.

Case to tryWhat your result should demonstrate
Change sessions while keeping minutesPerSession fixedThe displayed total is recalculated and remains numeric until formatting
Zero sessionsPreserve numeric zero and false completion
Wrong-type assignmentChecking rejects it without running the program

If changing sessions does not change the minutes in your sentence, you typed the total instead of calculating it. Only the wrong-type case is caught by Check types; the other two need you to compare the output with your prediction.

Your turn

Exercise

Checkpoint: Study Receipt: practice

Print Functions: 3 sessions, 60 minutes, done=false. Use topic="Functions", sessions=3, minutesPerSession=20 and completed=false; calculate the total instead of typing 60 into the output.

Your workspaceTypeScript
// Plan four values, calculate the total, and format the receipt.

Enable JavaScript to edit and type-check this example.

Hint 1: the idea

Keep the numeric calculation separate from the display sentence.

Hint 2: a first step

Declare sessions and minutesPerSession before creating totalMinutes.

Show one solution
One possible solutionTypeScript
const topic: string = "Functions";
const sessions: number = 3;
const minutesPerSession = 20;
const completed = false;
const totalMinutes = sessions * minutesPerSession;

console.log(
  `${topic}: ${sessions} sessions, ${totalMinutes} minutes, done=${completed}`
);

Enable JavaScript to edit and type-check this example.

Text
Functions: 3 sessions, 60 minutes, done=false

totalMinutes is calculated, so changing sessions to 4 prints 80 without touching the sentence. Two values are annotated as the brief asks and two are inferred; all four are const because nothing is reassigned. The checker would reject const sessions: number = "3", but it cannot tell whether 60 is the right total; your prediction does that.

Change it and explain it

Test zero sessions and a different topic. Would the checker reject negative sessions? Explain why not. Finish by writing a two-sentence explanation of inference and of what the compiler does before JavaScript runs. If you needed the full solution, redo the receipt tomorrow using reading sessions instead.

Was this article helpful?

Your response is saved on this device.