From d9c007e20642705e9c16f58af1b7349a2482a73b Mon Sep 17 00:00:00 2001 From: zepp Date: Sun, 2 Feb 2025 08:08:08 -0500 Subject: [PATCH] refactor js begin building out script with separate functions with specific behavior account for note needing to be interacted with first before other items can be clicked on --- cafe-events/valentines-day-25/script/script.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cafe-events/valentines-day-25/script/script.js b/cafe-events/valentines-day-25/script/script.js index d7e418b..41d80d2 100644 --- a/cafe-events/valentines-day-25/script/script.js +++ b/cafe-events/valentines-day-25/script/script.js @@ -13,10 +13,17 @@ const notesForEmma = { tileTwelve: "person", }; +const note = document.querySelector(".read-this"); const tiles = document.querySelectorAll(".tile"); -tiles.forEach((el) => { - el.addEventListener("click", () => { - console.log(`${notesForEmma[el.className.split(' ')[0]]}`); +note.addEventListener("click", () => { + tiles.forEach((el) => { + el.addEventListener("click", () => { + displayNote(el); + }); }); -}); \ No newline at end of file +}); + +const displayNote = (noteName) => { + console.log(`${notesForEmma[noteName.className.split(' ')[0]]}`); +}; \ No newline at end of file