im working on the bird watcher exercise and I’m struggling to see where my logic is falling apart when calculating the number of birds in a specific week
Implement a function birdsInWeek
that accepts an array of bird counts per day and a week number. It returns the total number of birds that you counted in that specific week. You can assume weeks are always tracked completely.
the task then shows the following example
birdsPerDay = [2, 5, 0, 7, 4, 1, 3, 0, 2, 5, 0, 1, 3, 1];
birdsInWeek(birdsPerDay, 2);
// => 12
My code is as follows:
let totalBirdsInWeek=0;
let startingPoint
if (week>1){
startingPoint=week*7
}else{
startingPoint=0
}
for(let arrayIndex=startingPoint; arrayIndex < birdsPerDay.length; arrayIndex++){
totalBirdsInWeek = totalBirdsInWeek + birdsPerDay[arrayIndex]
if(arrayIndex===startingPoint+7){
break;
}
}
return totalBirdsInWeek
}
I do not want the answer but a hint or confirmation of whether I’m on the right track would be great!