Skip to content

Commit

Permalink
Refactor script
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleA99 committed Aug 23, 2023
1 parent 8731a2c commit b787c74
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
let gridSize = "";

// Selects the element with the ID "grid-container" and assigns it to the variable gridContainer.
let gridContainer = document.querySelector("#grid-container");
const gridSize = "";
const gridContainer = document.querySelector("#grid-container");

/**
* Creates a grid of div elements in the specified container, with each cell changing color when hovered over.
* @param {number} gridSize - The size of the grid (number of rows and columns)
*/
const createGrid = (gridSize) => {
for (let i = 0; i < gridSize * gridSize; i++) {
// Creates a div and assigns it to gridTile
const gridTile = document.createElement("div");
// gridTile is given the class gridTileContent
gridTile.classList.add("gridTileContent");
Expand Down Expand Up @@ -58,10 +55,8 @@ const promptGridSize = () => {
clearGrid();

const gridValue = prompt("Please specify the desired grid size. E.g. 64 specifies a 64x64 grid.");
// Converts gridSize value from a string to a number
const gridSize = parseInt(gridValue);

// Throws an error when grid sizes exceed the maximum, 100x100 grid size
try {
if (gridSize > 100) throw new Error("exceeds maximum grid size of 100x100");
// Calls createGrid() and passes gridSize as an argument
Expand Down

0 comments on commit b787c74

Please sign in to comment.