Skip to content
Advertisement

TOP Etch-a-sketch grid resizing

I’m trying to complete The Odin Project’s Etch-a-Sketch challenge and am currently stuck with trying to resize the divs that make up the sketchpad. The app creates a 16×16 grid by default, and when pressing the erase button it asks for a number. It should then recreate the grid based on that number. However, after giving a number the size of the sketchpad is reduced. I have noticed that the number of empty divs created is always 256. Link to codepen for clarification: https://codepen.io/eerolli/pen/abELQbp

Any help as to how I could get the size of the pad to stay the same regardless of the number of divs inside it is greatly appreciated.

Edit: It should probably be noted, that the app works fine when I enter a number equal to or lower than 16.

html:

JavaScript

javascript:

JavaScript

Advertisement

Answer

You were super close … you just need to call the create grid function again after the input prompt, and pass the new size/number the user entered as the argument ;D


Edit: Ah yeah, I didn’t notice it got stuck in a loop. I’ve refactored a little and added a couple of comments, hopefully helps.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement