Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics Hello, JavaScript! JavaScript Practice Challenge

sangdon jang
sangdon jang
501 Points

how do i change the sequence of alert script

?

sangdon jang
sangdon jang
501 Points

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JavaScript Basics – Challenge</title> <link href="css/style.css" rel="stylesheet">

</head>

<body>

<main>
  <h1>Hello, JavaScript!</h1>

  <script>alert("Warning! This message will self-destruct in");</script>
  <script>alert("3....")</script>
  <script>alert("2......")</script>
  <script>alert("1....")</script>
</main>

<script src="js/script.js"></script> 
<script>console.log("messege destroyed")</script>

</body> </html>

Do you want to make it different than how Guil wants it to be? It looks like your code follows the sequence that it's supposed to. :thumbsup:

2 Answers

Hi. Do you mean like this:

<!DOCTYPE html> 
<html> 
<head> <meta charset="utf-8">
     <title>JavaScript Basics – Challenge</title> 
    <link href="css/style.css" rel="stylesheet">
</head>

<body>

<main>
  <h1>Hello, JavaScript!</h1>

  <script>alert("Warning! This message will self-destruct in");</script>
  <script>alert("1....")</script>  
  <script>alert("2....")</script>
  <script>alert("3....")</script>

</main>

<script src="js/script.js"></script> 
<script>console.log("messege destroyed")</script>

You can type whatever order you want when the inner HTML is hardcoded, like in your example above.

you can also write less code by looping (backward)

alert("Warning The message will self destruct in ");

for(let i = 3; i >= 1; i--){
  alert(`${i}..`);
}


document.querySelector("h1").textContent = "🔥BOOM!🔥";
console.log("message destroyed!");

Just wondering, but within the for loop, why was alert written as "alert(`${i}..');" ? I understand 'i' is the value iteration variable, but I don't understand the rest of the Syntax. Thanks :)