Arrays and loops
An array stores a list of values in one variable: let scores = [12, 7, 20];. Each item has a position called an index, starting at 0, so scores[0] is 12. scores.length tells you how many items there are.
A for...of loop runs once for each item: for (const s of scores) { … }. Inside the loop, s is the current item.
A common pattern is the running total: start at 0, then add each item inside the loop.
Example
let prices = [4, 10, 6];
let total = 0;
for (const price of prices) {
total = total + price;
}
console.log("Items:", prices.length);
console.log("Total:", total);
total += n is a short way to write total = total + n.Your tasks
0 of 3 done- sum([1, 2, 3]) returns 6Expected 6, got undefined
- sum([]) returns 0Expected 0, got undefined
- countAbove([5, 12, 8, 20], 9) returns 2Expected 2, got undefined
Tutor
The tutor guides you toward the answer instead of handing it over. It uses your own Claude usage.
Quick check
What is ["a", "b", "c"][2]?
undefined
No problems found. Unclosed tags, missing semicolons and errors show up here in plain words.