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) } } }

3rd May 2017, 5:36 PM
Elio Pereira
Elio Pereira - avatar
3 odpowiedzi
+ 4
call the function? occurrence(bowl);
3rd May 2017, 5:44 PM
Burey
Burey - avatar
+ 3
you didn't call the occurrence function
3rd May 2017, 5:51 PM
Apel Mahmod
Apel Mahmod - avatar
+ 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();
3rd May 2017, 11:33 PM
Calviղ
Calviղ - avatar