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 The Solution

Preview page is just blank white. Not even the first alert is showing

I decided to test my code halfway through and I'm glad I did because something's not right! Here is what I have so far. Why isn't even the first alert popping up?

alert("Let's do some math!"); var visitorAnswer1 = prompt("Give me a number, any number!"); convertedAnswer1 = parseFloat(visitorAnswer1);

var visitorAnswer2 = prompt("Anotha one!"); convertedAnswer2 = parseFloat(visitorAnswer2);

var add = convertedAnswer1 + convertedAnswer2; var subtract = convertedAnswer1 - convertedAnswer2; var multiply = convertedAnswer1 * convertedAnswer2; var divide = convertedAnswer1 / convertedAnswer2;

var message = "Simple math with the numbers" + convertedAnswer1 + " and " + convertedAnswer2 + "</h1>";

document.write(message);

Nik Oaks
Nik Oaks
8,056 Points

You might have to define the converted answer variables or simply assign that value back to the original visitor answer. And you never opened the h1 tag in the message there is only a closing tag

2 Answers

Cameron Childres
Cameron Childres
11,818 Points

Hi Esther,

Your alert code is valid so there's something else going on here.

Two things to check first:

  • Are your files saved?
  • Is your script linked in index.html? (The file doesn't start with the link in place, they show adding it about 10s in to the video.)

Hi Esther!

I tested it here:

https://www.w3schools.com/js/tryit.asp?filename=tryjs_array

With this code:

<!DOCTYPE html>
<html>
<body>

<h2>Simple Math</h2>

<script>
alert("Let's do some math!");
var visitorAnswer1 = prompt("Give me a number, any number!");
convertedAnswer1 = parseFloat(visitorAnswer1);

var visitorAnswer2 = prompt("Anotha one!");
convertedAnswer2 = parseFloat(visitorAnswer2);

var add = convertedAnswer1 + convertedAnswer2;
alert(add);
var subtract = convertedAnswer1 - convertedAnswer2;
alert(subtract);
var multiply = convertedAnswer1 * convertedAnswer2;
alert(multiply);
var divide = convertedAnswer1 / convertedAnswer2;
alert(divide);

var message = "Simple math with the numbers " + convertedAnswer1 + " and " + convertedAnswer2 + "</h1>";

document.write(message);

</script>

</body>
</html>

And it worked fine.

Go to the link, overwrite the code in the left panel with my code and run it and you'll see.

I hope that helps.

Stay safe and happy coding!