Skip to content

Commit 2e9861c

Browse files
committed
Make the color picker able to change the stroke color
1 parent b1aa7ea commit 2e9861c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Diff for: script.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
const DEFAULT_SIZE = 16;
33
const DEFAULT_COLOR = '#000000';
44

5+
// List of variables
6+
let currentColor = DEFAULT_COLOR;
7+
58
// Create a grid of squares on the canvas
69
const canvas = document.querySelector('.canvas');
710
function createGrid(size) {
@@ -32,7 +35,7 @@ canvas.addEventListener('mousedown', (e) => {
3235
canvas.addEventListener('mousemove', (e) => {
3336
console.log(e);
3437
if (e.buttons === 1 && e.target.classList.contains('square')) {
35-
e.target.style.backgroundColor = DEFAULT_COLOR;
38+
e.target.style.backgroundColor = currentColor;
3639
}
3740
});
3841

@@ -45,4 +48,10 @@ resetButton.addEventListener('click', () => {
4548
});
4649
});
4750

51+
// Update the current color when the color picker is changed
52+
const colorPicker = document.querySelector('#colorPicker');
53+
colorPicker.addEventListener('change', () => {
54+
currentColor = colorPicker.value;
55+
});
56+
4857
createGrid(DEFAULT_SIZE);

0 commit comments

Comments
 (0)