+ 3

Uncaught TypeError: Cannot read property '0' of undefined[es6 learning]

That error occurs most often in my codes... I spent an hour thinking what's wrong. I'm trying to assign each of the divs an action function changing it's color to black and I'm getting an annoying error: Cannot read property '0' of undefined. Please help, my code: https://code.sololearn.com/WZ7tjp0roE7X/#html

7th May 2018, 5:23 PM
Amadeus
Amadeus - avatar
6 Antworten
+ 3
Hi Amadeus, area getter is called without brackets in the lesson, but declared with
8th May 2018, 6:21 AM
Mike Choy
Mike Choy - avatar
+ 5
but you're for sure right: not this.cells, but this.Cells
8th May 2018, 6:19 AM
Amadeus
Amadeus - avatar
+ 4
Mike Choy Oh thanks, now I understood. As in c#
8th May 2018, 6:23 AM
Amadeus
Amadeus - avatar
+ 3
Hi Amadeus Just had a quick look, and its failing on this.cells should it be this.Cells? for(let m=0; m<this.yCount; m++){ $("body").append("<div></div>"); this.cells[l][m] = $("body div").last(); $(this.cells[l][m]).addClass("cell"); $(this.cells[l][m]).css({
7th May 2018, 10:05 PM
Mike Choy
Mike Choy - avatar
+ 2
Hi, Mike Choy Thanks for support, but in the lesson "class methods" https://www.sololearn.com/learn/518/?ref=app they used the following getter for the calcArea method... get area() { return this.calcArea(); } calcArea() { return this.height * this.width; }
8th May 2018, 6:16 AM
Amadeus
Amadeus - avatar
+ 1
Hi Amadeus And finally you are calling your getters wrong; Should be board.Create; board.AllowMark; no brackets as its not a method. It runs and paints one big long vertical bar, so some more work to do but hopefully that gets you going again
7th May 2018, 10:14 PM
Mike Choy
Mike Choy - avatar