Can someone help me with this question? I'm struggling:
Create an array called 'bowl' with the following items:
["jelly-bean", "m&m", "m&m", "chocolate", "m&m", "jelly-bean", "m&m", "m&m", "jelly-bean"]
Then, declare three variables:
jbOccur
,mOccur
,chocOccur
. Set each to 0.- Lastly, write a function named 'occurrence' that iterates through the 'bowl'
array and updates the values of the three variables according to their occurrences.
(Hint: after running the 'occurrence' function,
jbOccur
should be 3).
This is what I've come up with so far. Any feedback would be appreciated:
var bowl = ["jelly-bean", "m&m", "m&m", "chocolate", "m&m", "jelly-bean", "m&m", "m&m", "jelly-bean"]
var jbOccur = 0
var mOccur = 0
var chocOccur = 0
var occurrence = function (jbOccur, mOccur, choOccur){
for (var i = 0; i < bowl.length; i++) {
console.log(bowl[jbOccur, mOccur, chocOccur])
}
};