+ 1
Hey! Can somebody tell me what's wrong with this code?
Here it is: https://code.sololearn.com/WGpJ5r0I0E1E/?ref=app
2 Réponses
+ 2
Line 76 is the actual problem. There you are using for-of instead of for-in. In doing so the values of the line object are assign to x instead of the keys.
At the start of iterating over the line string/object:
for-of: x is "#" meaning that line[x] is line["#"] is null
for-in: x is 0 meaning that line[x] is line[0] is "#"
Something else to keep in mind is that when using for-in, x is type string meaning you need to convert x to type number
Another problem is on line 90 if false then return elem.originalChar, there is no such property in the elem object.
You also have a naming conflict with Map, which is a standard built-in object of javascript, this will cause problems soon or letter.
0
In your code legend is empty object, thats why you get error (not constructor)
In line at end you set this legend (this object here, second parameter)
var world = new World(plan, {"#": Wall, "o": Entity});
But problem is your Wall dont exist (it is empty function), you started to create Wall but didnt finished, and you need here probably "new" keyword. If I change Wall to string "wall" and set new Entity, legend is not anymore empty object, now it have string wall and some object in place of Entity.
To check object values in sololearn you can use console.log(JSON.stringify(yourObject))
Even when you finish Wall, you cant use object as constructor, you need to create constructor with function or class, like you did for others.
So to fix add new keyword before Entity, finish Wall function, if this is constructor add also new keyword.
Not sure what you are doing in that line 66, but you need this legend to be constructor (you cant use new keyword if this is just normal object)