diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..12a11db Binary files /dev/null and b/.DS_Store differ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8a51f7e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5503 +} diff --git a/DOM-Manipulation/domscript.js b/DOM-Manipulation/domscript.js new file mode 100644 index 0000000..acbdb01 --- /dev/null +++ b/DOM-Manipulation/domscript.js @@ -0,0 +1,34 @@ +let redDiv = document.getElementById("redBox"); +let blueDiv = document.getElementById("blueBox"); +let yellowDiv = document.getElementById("yellowBox"); + +// redDiv.onclick = () => console.log("It is RED"); //* <-----SHORTER WAY to right 'onclick' functions +// blueDiv.onclick = () => console.log("It is BLUE"); +// yellowDiv.onclick = () => console.log("It is Yellow"); + +const squares = document.querySelectorAll(".colorSquare"); +console.log(squares); + +//* forEach + +const timesClicked = { red: 0, yellow: 0, blue: 0 }; //* <----Object keeping track of how many times a button is clicked + +squares.forEach((square) => { + //* Loop through the squares + square.onclick = () => { + //* Event Listener for the button + timesClicked[square.value] += 1; //* <---Updating the [key.values] and adding 1 + square.innerText = timesClicked[square.value]; //* Changing the innerText + }; +}); + +function clearScores() { + timesClicked.red = 0; + timesClicked.blue = 0; + timesClicked.yellow = 0; + squares.forEach((square) => { + square.innerText = ""; + }); +} +const clearGameBtn = document.getElementById("clearGame"); +clearGameBtn.onclick = () => clearScores(); diff --git a/DOM-Manipulation/index.html b/DOM-Manipulation/index.html new file mode 100644 index 0000000..742d402 --- /dev/null +++ b/DOM-Manipulation/index.html @@ -0,0 +1,35 @@ + + +
+ + + + +