← ⚡ JavaScript World
⚡ Sum It All
You can practise without a player, but pick a player to score points!
📖 The mission
Today you unlock
Loops inspect each item
Many levels use a loop: start with a simple value, visit each item, update the answer, then return it at the end.
💡 Hint ladder
- A for...of loop can visit every number: for (const n of numbers) { ... }
- Start a total at 0 and add each number to it.
🧪 Coach checks
- ◯ adds 1+2+3
- ◯ empty array is 0
- ◯ single number
- ◯ negative numbers
Live coach
Getting ready
☆☆☆
💬 A loop visits every item in an array. Watch the total grow.
function countItems(items) {
let count = 0;
for (const item of items) {
count = count + 1;
}
return count;
}
console.log(countItems(["a", "b", "c"])); // 3
📟 It printed:
Nice — you saw it work!
📟 Output
🧩 Gaps filled! Ready to write it all yourself?