Hello everyone,
I was reading the JS Objects in Detail article over at javascriptissexy, and about one-third down, it says:
If you have done the Learn JavaScript Properly course, you would have seen the lessons in the Code Academy used this first pattern frequently: [code is below]
This program utilizes forEach
. The first time I saw this page I hadn’t done all the exercises, but now I’m done with the track and I don’t remember using it.
Looking at the program I can sort of understand how it works, and I tried to read MDN’s forEach
page but am still confused.
Can someone please explain what forEach
does in an easy-to-understand way?
Thank you,
frisby
Note: just to be clear, this post is not a complaint about forEach “missing” in the lessons. I understand Codecademy and JiSS are separate entities. Seeing it referenced as something I should know simply instigated in me a desire to know.
<Below this line, add a link to the EXACT exercise that you are stuck at.>
<In what way does your code behave incorrectly? Include ALL error messages.>
```function Fruit (theColor, theSweetness, theFruitName, theNativeToLand) {
this.color = theColor;
this.sweetness = theSweetness;
this.fruitName = theFruitName;
this.nativeToLand = theNativeToLand;
this.showName = function () {
console.log("This is a " + this.fruitName);
}
this.nativeTo = function () {
this.nativeToLand.forEach(function (eachCountry) {
console.log(“Grown in:” + eachCountry);
});
}
}
<do not remove the three backticks above>