Skip to content

Commit c3343b4

Browse files
committed
completed DOM exercise
1 parent 4a7b752 commit c3343b4

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

dom-and-events/exercises/script.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1-
function init () {
2-
const missionAbort = document.getElementById("abortMission");
3-
const button = document.getElementById("liftoffButton");
4-
const paragraph = document.getElementById("statusReport");
5-
6-
// Put your code for the exercises here.
7-
8-
}
1+
function init() {
2+
const missionAbort = document.getElementById("abortMission");
3+
const button = document.getElementById("liftoffButton");
4+
const paragraph = document.getElementById("statusReport");
5+
6+
// Put your code for the exercises here.
7+
button.addEventListener("click", function () {
8+
paragraph.innerHTML = "Houston, we have liftoff!";
9+
});
10+
11+
missionAbort.addEventListener("mouseover", function (event) {
12+
const element = event.target;
13+
element.style.backgroundColor = "red";
14+
});
15+
16+
missionAbort.addEventListener("mouseout", function (event) {
17+
event.target.style.backgroundColor = "";
18+
});
19+
20+
missionAbort.addEventListener("click", function() {
21+
const confirmed = window.confirm("Are you sure you want to abort the mission?");
22+
if (confirmed) {
23+
paragraph.innerHTML = "Mission aborted! Space shuttle returning home";
24+
} else {
25+
paragraph.innerHTML = "Mission continues. Stay on course!";
26+
}
27+
});
28+
29+
};
930

1031
window.addEventListener("load", init);

0 commit comments

Comments
 (0)