0
Where am I messing up?
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; function occurrence(bowl){ for (var i=0; i<bowl.length; i++) { if (bowl[i]=="jelly-bean") { jbOccur++; console.log(jbOccur) } else if (bowl[i]=="m&m") { mOccur++; console.log (mOccur) } else if(bowl[i]=="chocolate") {chocOccur++; console.log(chocOccur) } } }
3 odpowiedzi
+ 4
call the function?
occurrence(bowl);
+ 3
you didn't call the occurrence function
+ 3
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;
function occurrence(){
for (var i=0; i<bowl.length; i++)
{
if (bowl[i]=="jelly-bean")
jbOccur++;
else if (bowl[i]=="m&m")
mOccur++;
else if(bowl[i]=="chocolate")
chocOccur++;
}
console.log(jbOccur)
console.log (mOccur)
console.log(chocOccur)
}
occurrence();