Skip to content

๐Ÿง‘๐Ÿพโ€๐Ÿ’ป Find the bug

Starter Analyse ๐Ÿ’ป Computational Thinking ๐Ÿค– AI Thinking and AI Literacy โฑ about 10 minutes 10 points

The challenge

This JavaScript function should add up all numbers in an array, but it returns NaN. Find the bug, explain why it happens, and give the fixed line.

function sum(nums) {
  let total = 0;
  for (let i = 0; i <= nums.length; i++) {
    total += nums[i];
  }
  return total;
}

Instructions

  1. 1Trace what happens on the last loop.
  2. 2Explain the cause in one or two sentences.
  3. 3Write the corrected line.

Rules

  • Explain in your own words โ€” copying an AI answer without understanding will not score the explanation criterion.

Success criteria

Your submission is marked against these criteria only.

  • Gives the correct fix Checked automatically 4 pts
  • Identifies the cause Checked automatically 3 pts
  • Explains the NaN Checked automatically 1 pt
  • Clear explanation in your own words Needs AI review โ€” not configured yet, so not assessed 2 pts
words

Your submission is private. It is marked only against the success criteria โ€” not on whether an AI produced an answer.

What an AI replied to your prompt

For comparison only โ€” this reply does not affect your score. Does it give you what you asked for?