![enter image description here][1]
function setFood () {
var empty = [];
for (var x=0; x<grid.width; x++) {
for (var y=0; y>grid.height; y++) {
if (grid.get(x,y) === EMPTY) {
empty.push({x:x, y:y});
}
}
}
};
While watching a tutorial on YouTube about creating a snake game, I stumbled upon this code snippet while the developer was writing a function.
This has sparked my curiosity and I have several questions that I am eager to find answers to in order to deepen my learning.
First of all, what does the .get method do? My search results mentioned jQuery, but there was no reference to using the jQuery library. What impact does it have on plain JavaScript code? Also, what is the significance of EMPTY
? Is it a predefined term in JavaScript equivalent to 0
or `null`? Lastly, why is the creator using brackets within the push method? What exactly does it add to the empty array? And what do x:x
and y:y
signify?
I apologize for bombarding with questions, but I lack direct access to people who can help me with coding queries apart from the coding community itself.