I'm brand new to this so if I'm not explaining the problem as I should, please let me know!
I'm basically using Twilio Quest as a way to start learning Javascript and have gotten myself a little stuck.
The challenge is to test the conditions of an array of strings and increase the value of a variable every time a certain string appears ... then return the value of said variable at the end of the function.
Here's what I have:
let freightItems = ['contraband', 'clear', 'contraband', 'clear'];
freightItems.forEach(scan);
function scan(freightItems) {
const contrabandCount = 0;
if (freightItems.element == 'contraband') {
contrabandCount + 1;
}
return contrabandCount;
}
The error I'm getting when I submit the code to TwilioQuest is:
Your function returned a number, but not the value we were looking for. Your function should examine every item in the input array, and return the total number of times the string "contraband" appeared.
contrabandCount + 1;doesn't change the value ofcontrabandCount. You have to store the result incontrabandCount:contrabandCount = contrabandCount + 1(orcontrabandCount += 1)freightItems.element. Also a return inforEachcallback has nowhere to return to