Skip to content

Checkpoint: Weekly Goal

The Course
•
20 min study

Your 20-minute checkpoint

Close the earlier examples. Spend two minutes writing the inputs, expected outputs, and steps in plain language. Use about eight minutes to build and test, then five to explain your choices and try the variation. Taking longer is normal: these are study budgets, not speed tests.

Combine repetition, decisions, and state. This problem deliberately changes the setting so you practice choosing the tools yourself.

Acceptance cases before you code

Before you write code, decide what each case below should print. Then work through them by changing the goal or the loop's range and pressing Run again. The exact-boundary case catches a different mistake from an ordinary one.

Case to tryWhat your result should demonstrate
Goal equal to the calculated total, then one higherThe exact boundary succeeds and the higher goal does not
Goal one minute above the totalReport not reached
No days in a bounded rangeLeave the accumulator at zero

When everything prints correctly, change >= to > on purpose and find the case that notices. Put it back, then say in one sentence which rule the mistake broke. If you cannot remember how to do a step, revisit that lesson before opening the solution.

Exercise

A weekly practice target

Practice 10 minutes on days 1–3 and 20 minutes on days 4–7. Print the total and whether the 100-minute goal is met. Derive the answer with a loop.

Your working space JavaScript
let total = 0;
// Visit days 1 through 7.
Hint 1: the idea

Choose the duration inside the loop, then update one total.

Hint 2: a first step

Use day <= 3 to distinguish the two schedules.

Show one solution
JavaScript
let total = 0;

for (let day = 1; day <= 7; day++) {
  if (day <= 3) {
    total += 10;
  } else {
    total += 20;
  }
}

console.log(total);

if (total >= 100) {
  console.log("Goal met");
} else {
  console.log("Keep practicing");
}
Text
110
Goal met

Change the goal to 110 and then 111. Explain the boundary before running. A second loop is unnecessary.

Change the requirements

Change the goal to 110 and then 111. Explain the boundary before running. A second loop is unnecessary.

Decide what to revisit

  • Can you explain each variable and the reason for each condition?
  • Did you check an empty, boundary, or changed input rather than only the supplied one?
  • Can you rebuild the essential part after closing the solution?

If you needed a hint, record the specific missing idea and revisit that lesson. Marking a page done records progress; it does not replace practice. Begin tomorrow by rebuilding one small part from memory.

Was this article helpful?

Your response is saved on this device.