let totalBirds = 0;
let start = (week - 1) * 7;
let end = start + 7;
// Slice out the correct week
let weekDays = birdsPerDay.slice(start, end);
for (let i = 0; i < weekDays.length; i++) {
totalBirds += weekDays[i];
}
It keeps spitting birdsPerDay.slice is not a function
function birdsInWeek(birdsPerDay, week) {
let totalBirds = 0;
let start = (week - 1) * 7;
let end = start + 7;
// Slice out the correct week
let weekDays = birdsPerDay.slice(start, end);
for (let i = 0; i < weekDays.length; i++) {
totalBirds += weekDays[i];
}
return totalBirds;
}
That’s because there’s no slice function/method on the birdsPerDay object birdsPerDay is array-like but not actually an array. You can index into it but not use methods like slice().
Hey Isaac, thank you for your input.
I’m following the instruction that that method ought to work on the birdsPerDay, since it will receive an array as per the instruction.
I will be following on what you have said, and I will update this thread.
The instructions are a bit misleading. The function receives an array-like object which you can use to access specific values by index. But you cannot use array methods on it.
Exactly.
I have solved it and now I think it might have been done deliberately to allow folks grind at the problem, for problem solving sake, just my thoughts.
If it ought to be very specific as you have said, instead of “Implement a function totalBirdCount that accepts an array that contains the bird count per day.” Do you think I should open an issue and P.R on it?
You shouldn’t open an issue. Exercism uses the forum to track issues. You shouldn’t open a PR without first proposing a change on the forum and having a track maintainer requesting you PR the change.