Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit 06896e5

Browse files
committed
feat: Coding Challenge 2 of Functions Section Done
1 parent 0f40421 commit 06896e5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

04-functions/script.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,27 @@ answerPollDom.addEventListener('click', () =>
7575
const displayResults = poll.displayResults;
7676
displayResults.bind({ answers: [5, 2, 3] }, 'string')();
7777
displayResults.bind({ answers: [1, 5, 3, 9, 6, 1] })();
78+
79+
// Coding Challenge 2
80+
81+
/*
82+
1. Take the IIFE below and at the end of the function, attach an event listener that
83+
changes the color of the selected h1 element ('header') to blue, each time
84+
the body element is clicked. Do not select the h1 element again!
85+
2. And now explain to yourself (or someone around you) why this worked! Take all
86+
the time you need. Think about when exactly the callback function is executed,
87+
and what that means for the variables involved in this example.
88+
GOOD LUCK 😀
89+
*/
90+
91+
(function ()
92+
{
93+
const header = document.querySelector('h1');
94+
header.style.color = 'red';
95+
96+
header.addEventListener('click', () =>
97+
{
98+
header.style.color = 'blue';
99+
console.log('blue');
100+
});
101+
})();

0 commit comments

Comments
 (0)