Describe the bug
When running tests in the web editor, array methods likeforEachare unavailable inside the solution function. The test runner reportsTypeError: birdsPerDay.forEach is not a function, even though the passed argument appears to be an array inconsole.log.To Reproduce
- Open the “Bird Watcher” exercise in the web editor (JavaScript track).
- Submit a solution using
forEach:export function totalBirdCount(birdsPerDay) {
let total = 0;
birdsPerDay.forEach(element => { total += element; });
return total;
}
- Click “Run Tests”.
- See error:
TypeError: birdsPerDay.forEach is not a functionConsole output also shows:
[worker] could not be made Qh: /javascript-browser-test-runner-worker.mjs did not yield a valid worker
Expected behavior
forEachshould work normally on the array passed by the test runner.Workaround
Using aforloop with index access works, since it doesn’t rely on array prototype methods.Environment
- Browser: Chrome (with DevTools open)
- Track: JavaScript
- Exercise: Bird Watcher
The instructions say,
To practice, use a
forloop to solve each of the tasks below.
and
Implement a function
totalBirdCountthat accepts an array-like object that contains the bird count per day.
This is by design and intentional. You should be using for.
2 Likes