The Stack Overflow podcast is back! Listen to an interview with our new CEO.

New answers tagged

1

You could use an ENUM instead of a String for the type of piece. The colors (white/black "#fff"/"#000") should be declared as variables at the top, to make it easier to change. Try to avoid magic numbers / Strings. For example, why multiply by 0.9 here? const size = Math.min(window.innerWidth, window.innerHeight) * 0.9; You should use methods more often. ...


4

Before anything else, the tutorial you're referencing is this: https://www.freecodecamp.org/news/d3-and-canvas-in-3-steps-8505c8b27444/ By reading the tutorial you'll see that the elements we'll create for manipulating the canvas>... ... don’t live in the DOM but only in memory (in a ‘virtual’ DOM) and describe the life-cycle of these elements in a ...


1

This code looks like a good start. Some variable could be declared with const because they aren't re-assigned - e.g. canvas, snake if the first line of newSnake() was changed to snake.length = 0;. This helps avoid accidental re-assignment in the future. The function name pGame could be improved for readability to be more descriptive of what it does - ...


Top 50 recent answers are included