Repository navigation
#028 Buggy Code3
Adam Kubiś edited this page Oct 28, 2026
·
1 revision
Fix the code in the code tab to pass this challenge (only syntax errors).
Current source and tests | Catalog | Testing and tooling
From the cloned repository root, after installing dependencies:
node "Edabit/028 Buggy Code3.js"Assertions are kept alongside the implementation and throw on failure. A successful run exits with code 0. Run every exercise with npm test or both lint and tests with npm run check.
This is the complete executable file, including its imports and inline test cases. Run it from the repository, not as an isolated file copied out of the wiki. Line endings and trailing whitespace are normalized; executable tokens are unchanged.
//Fix the code in the code tab to pass this challenge (only syntax errors).
function sumArray(arr) {
let sum = 0; // Initialize sum to 0
for (const value of arr) {
sum += value; // Add each element of the array to sum
}
return sum; // Return the final sum
}
import * as Test from '../testHelper.js';
Test.assertEquals(sumArray([1, 2, 3, 4, 5]), 15)
Test.assertEquals(sumArray([-1, 0, 1]), 0)
Test.assertEquals(sumArray([0, 4, 8, 12]), 24)