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 (Retired) Storing and Tracking Information with Variables Introducing Variables

Devon Deason
Devon Deason
7,061 Points

Why don't i get two alert boxes?

I'm only getting the hello alert box, why?

var message = "Hello!";
alert(message);
message = "welcome to Javascript basics";
alert(message);

javascript interpret the code and running it line by line, syntax commands are executed one after another meaning one command only executes if and only if the previous command finished.

alert - native method to create a window object, when you type alert the browser creates a new window object for and place the argument string in it to display.

the javascript interpreter is waiting for the browser to return from its action to continue interpret the rest of your code.

5 Answers

jason chan
jason chan
31,009 Points

Might be IT issue then. Please clear browser history or try different browser to see if it works. cache is the greatest enemy in the IT world.

Devon Deason
Devon Deason
7,061 Points

Cleared the cache and we're just fine now! Thanks! Damn you cache!!! :)

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Devon,

Your code is correct, and it runs fine when I run it in my console. I got the first "Hello" ... hit enter and got the second "welcome to Javascript basics".

So, I'm not sure why it isn't working for you. Everything is fine!

:)

Aaron HARPT
Aaron HARPT
19,845 Points

You need to change your variable names from the same thing.

It could also be browser thing. In chrome if you have multiple alerts it will give you a check box to ignore anymore alerts that pop up.

Just do not click the check box referenced above by Donald Brunais and you should be fine.

jason chan
jason chan
31,009 Points

variables are like batteries you store information in those batteries. But you stored message a second time so that battery is storing something new.

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Aaron HARPT & jason chan you are correct, but where Devon is in the instructions, he is told to do it exactly like that. Dave is teaching how you can overwrite variables (in the video) and uses the two separate alert boxes to illustrate that. So, Devon should be getting 2 boxes with the 2 different messages.

:)