Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed JavaScript Basics!
You have completed JavaScript Basics!
Preview
This video covers one solution to the JavaScript practice challenge.
Self-destructing Message Solution
// 1. Display an alert dialog with the content: "Warning! This message will self-destruct in"
alert("Warning! This message will self-destruct in");
// 2. Display a "3... 2... 1..." countdown using 3 alert dialog boxes
alert("3...");
alert("2...");
alert("1...");
// 3. This statement selects the <h1> element and replaces its text with "BOOM!".
document.querySelector("h1").textContent = "🔥BOOM!🔥";
// 4. Log "Message destroyed!" to the console
console.log("Message destroyed!");
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Now, I'll show you my solution which
you can also copy from the teacher's
0:00
notes with this video.
0:02
To create the self-destructing
message program, I first use the alert
0:03
command to pop up an alert dialog
that displays the message, Warning!
0:08
This message will self-destruct in.
0:13
The alert message, as you've learned,
should be between quotation marks.
0:16
And it doesn't matter for now if they're
either single or double quotation marks.
0:20
I used double-quotes.
0:24
Next, I displayed the 3, 2, 1 countdown
using a series of three alert commands.
0:26
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up