Seeking assistance with a Javascript problem due to being new to the language.
I am trying to create a function that calculates feedback scores based on specific criteria. The goal is to iterate through an array containing nested arrays and increment the properties negative
, neutral
, or positive
based on the score given (below 3, between 4-6, or 7-10 respectively).
However, all I'm seeing in the console log is:
{positive: 0, negative: 0, neutral: 0}
Clearly, this output is not what I expected. What am I doing wrong?
function gatherFeedback(feedbackArray) {
let result = {
positive: 0,
negative: 0,
neutral: 0
};
if (feedbackArray > 0) {
for (let i = 0; i < feedbackArray; i++) {
if (feedbackArray[i][1] >= 7) {
result.positive++
} else if (feedbackArray[i][1] <= 3) {
result.negative++
} else if (feedbackArray[i][1] > 3 && feedbackArray < 7) {
result.neutral++
}
}
}
return result;
}
console.log(gatherFeedback([
['feedback1', 10],
['feedback2', 3],
['feedback3', 6]
]))