Checkpoint: Data & Logic
Reviewed & published by Brayan K
You've learned iterators, generators, strings, numbers, loops, conditionals and type coercion — let's combine them. Up to now each topic stood on its own. Real programs blend them: you loop over rows of text, slice and trim each field, convert strings to numbers, and branch on conditions to summarize the result.
Part of the free JavaScript course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
In this checkpoint you'll build a small data-summarizer from scratch, then test your understanding with a quiz. No new syntax — just everything you already know, working together.
What You've Learned So Far
This checkpoint draws on the last seven lessons. Here's the toolkit you're about to use all at once:
🧠 Warm-Up: The Skills in Miniature
Before the big build, here's a tiny preview that touches every tool you'll need. Read it and predict the output — it's the whole checkpoint in eight lines:
That's the pattern — split, clean, convert, decide, report. Now scale it up to many rows.
🛠️ Build Challenge: CSV Sales Summarizer
You're given a multi-line string of CSV-ish sales data. Each line is product,quantity,price. The data is messy — there's a header row, some stray spaces, and one blank line. Your job is to parse and summarize it.
Build a program that prints:
- One line per product: Product — qty × $price = $lineTotal
- The total revenue across all rows (quantity × price, summed)
- The best-selling product by quantity
Requirements that exercise each skill:
- Loops: iterate the rows with for…of
- Strings: split on newlines and commas, trim each field
- Conditionals: skip the header and any blank line with continue
- Numbers/Coercion: convert quantity and price with Number(), format money with toFixed(2)
Start from the scaffold below. Try it yourself first, then reveal the solution to compare.
const data = `
product,quantity,price
Notebook, 12, 4.50
Pen, 40 , 0.99
Backpack, 3, 29.99
`;
// 1. Split into lines and drop empties (whitespace-only)
const lines = data.split("\n").map((l) => l.trim()).filter((l) => l !== "");
let totalRevenue = 0;
let bestName = "";
let bestQty = -1;
for (const line of lines) {
// 2. Skip the header row
if (line.startsWith("product,")) continue;
// 3. TODO: split the line into name, quantity, price (trim each!)
// 4. TODO: convert quantity and price to numbers
// 5. TODO: compute the line total and add it to totalRevenue
// 6. TODO: track the best-selling product by quantity
// 7. TODO: print "name — qty x $price = $lineTotal"
}
console.log("----------------------------");
// 8. TODO: print total revenue and the best seller
// Hint: Number(" 12 ") works because Number trims whitespace for you.✅ Reveal the Solution
Here's one clean way to do it. Notice how each step maps to a skill from the recap card:
Why it works: splitting on "\n" then filtering empties handles the blank line; map(f => f.trim()) cleans every field at once; Number() quietly trims and converts the digits; the Number.isNaN guard protects against malformed rows; and a single running bestQty comparison finds the top seller in one pass. That's all seven prior lessons cooperating in about twenty lines.
📝 Checkpoint Quiz
Answer each in your head first, then reveal to check. These pull directly from the last seven lessons.
1. What does "a,b,,c".split(",").length return?
4. Splitting on "," keeps the empty field between the two commas, producing ["a", "b", "", "c"] — four elements. This is why real parsers must decide whether to keep or drop empty fields.
2. What is the value of Number(" 7 ") and Number("7px")?
7 and NaN. Number trims surrounding whitespace, so " 7 " becomes 7. But it requires the whole string to be numeric, so "7px" fails and yields NaN. Use parseInt if you expect trailing units.
3. In the build, why do we use continue for the header instead of break?
continue skips only the header line and keeps processing the rest. break would exit the loop entirely, so no data rows would ever be summarized. continue = skip one; break = stop all.
4. What prints: console.log("3" + 2 * 2)?
34. Multiplication runs first (2 * 2 = 4), then "3" + 4 concatenates because one operand is a string, giving "34". Operator precedence and coercion together.
5. Which fallback keeps a valid 0 price: price || 9.99 or price ?? 9.99?
price ?? 9.99. ?? only falls back on null/undefined, so a free item priced at 0 survives. || would treat the falsy 0 as missing and wrongly replace it with 9.99.
6. Why does (0.1 + 0.2).toFixed(2) give "0.30" while 0.1 + 0.2 === 0.3 is false?
Floating-point can't store 0.1 and 0.2 exactly, so the sum is 0.30000000000000004, which is not strictly equal to 0.3. toFixed(2) rounds for display and returns the string "0.30". For money, work in integer cents.
Checkpoint Complete — Data & Logic!
- ✅ You combined loops, strings, numbers, conditionals and coercion in one real program
- ✅ You parsed messy CSV-ish text into clean, summarized data
- ✅ You guarded against blank lines, headers, and unparseable rows
- ✅ You tested your understanding with the checkpoint quiz
If the build clicked, you have a solid command of JavaScript's core data and logic.
Practice quiz
What does "a,b,,c".split(",").length return?
- 3
- 5
- 4
- It throws
Answer: 4. Splitting keeps the empty field between the two commas: ["a", "b", "", "c"] has 4 elements.
What is the value of Number(" 7 ")?
- 7
- NaN
- " 7 "
- undefined
Answer: 7. Number trims surrounding whitespace, so a clean numeric string converts to 7.
What does Number("7px") evaluate to?
- 7
- "7px"
- 0
- NaN
Answer: NaN. Number requires the whole string to be numeric; trailing letters make it NaN. Use parseInt for units.
In a loop, what is the difference between continue and break?
- continue stops the loop; break skips one
- continue skips the current iteration; break exits the loop
- They are identical
- continue only works in for-of
Answer: continue skips the current iteration; break exits the loop. continue skips just the current iteration; break exits the whole loop.
What does console.log("3" + 2 * 2) print?
- 34
- 10
- 7
- NaN
Answer: 34. Multiplication runs first (4), then "3" + 4 concatenates to "34" because one operand is a string.
Which fallback keeps a valid 0 price instead of replacing it?
- price || 9.99
- Both keep it
- price ?? 9.99
- Neither keeps it
Answer: price ?? 9.99. ?? only falls back on null/undefined, so a real 0 survives; || treats falsy 0 as missing.
Is 0.1 + 0.2 === 0.3 true or false in JavaScript?
- true
- false
- It throws
- Depends on the engine
Answer: false. Floating-point can't store 0.1 and 0.2 exactly; the sum is 0.30000000000000004, not 0.3.
What does (0.1 + 0.2).toFixed(2) return?
- the number 0.3
- "0.300000"
- 0.30000000000000004
- "0.30"
Answer: "0.30". toFixed rounds for display and returns a string, so you get the string "0.30".
What does parseInt("7px") return?
- NaN
- 7
- "7"
- 0
Answer: 7. Unlike Number, parseInt reads leading digits and stops at the first non-numeric character, giving 7.
What is the result of "5" === 5?
- true
- It coerces to true
- false
- It throws
Answer: false. === compares without coercion; a string and a number of different types are never strictly equal.
Continue this course
- Previous: Checkpoint: Core JavaScript
- Next: DOM Manipulation — Select and change HTML elements directly from JavaScript
- Quick reference: JavaScript cheat sheet
Frequently asked questions
What is a checkpoint lesson for?
A checkpoint pauses new material so you can prove the previous skills actually clicked. Instead of learning one isolated feature, you combine several — here, loops, string methods, conditionals, numbers, and coercion — into one realistic program. If you can build it, you're genuinely ready to move on.
I got stuck on the build challenge — is that bad?
Not at all. Getting stuck is where real learning happens. Try the challenge first without peeking, then reveal the solution and compare it to your attempt. Understanding why the model answer works is more valuable than getting it perfect on the first try.
Why parse CSV by hand instead of using a library?
Doing it manually cements the fundamentals: splitting on delimiters, trimming whitespace, converting strings to numbers, and guarding against bad rows. In production you'd often reach for a tested CSV parser to handle quoted fields and edge cases, but the core logic you practice here is exactly what those libraries do under the hood.
How should I check my answers on the quiz?
Answer each question in your head or on paper first, then expand the details to confirm. The explanations matter as much as the right letter — they connect the question back to the specific lesson concept, which is what helps it stick.