-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesigns.js
More file actions
57 lines (47 loc) · 1.75 KB
/
designs.js
File metadata and controls
57 lines (47 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* jshint esnext: true */
/** Defining variables
* Accessing the DOM using methods of the document object
* @chooseGrid select size input and assign to variable
* @gridHeight assign variable height
* @gridWidth assign variable width
* @designCanvas assign variable to grid sizes
* @pickColor select color
*/
const chooseGrid = document.querySelector("#sizePicker");
const gridHeight = document.querySelector("#inputHeight");
const gridWidth = document.querySelector("#inputWidth");
const pickColor = document.querySelector("#colorPicker");
const designCanvas = document.querySelector("#pixelCanvas");
// select color variant
pickColor.addEventListener("click", () => {});
// When size is submitted by the user, call makeGrid()
chooseGrid.onsubmit = function(event) {
event.preventDefault();
emptyGrid();
makeGrid();
};
function makeGrid() {
// Your code goes here
/** Declaring functions and attaching them to DOM objects as event listeners
* @columnCell creates grid squares when called
* @column - number of squares representing the width of the grid
* @row - number of squares representing the height of the grid
*/
for (let row = 0; row < gridHeight.value; row++) {
const tableRow = designCanvas.insertRow(row);
for (let column = 0; column < gridWidth.value; column++) {
const columCell = tableRow.insertCell(column);
columCell.addEventListener("click", colorSquare);
}
}
}
// clears grid on restart (submit)
function emptyGrid() {
while (designCanvas.firstChild) {
designCanvas.removeChild(designCanvas.firstChild);
}
}
// Color square using selected color pick
function colorSquare() {
this.setAttribute("style", `background-color: ${pickColor.value}`);
}