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
Shari Staten
11,540 PointsJavaScript Email Challenge
So, Dave sent this via email. I stopped getting alert/prompt after the third question. Here's my code:
// 2. Add an alert to announce the program with a message like "Let's do some math!" alert('Ready for some math?');
// 3. Create a variable and use the prompt() method to collect a number from a visitor var firstNumber = prompt('Please choose a number.');
// 4. Convert that value from a string to a floating point number firstNumber = parseFloat(firstNumber);
// 5. Repeat steps 3 and 4 to create a second variable and collect a second number var secondNumber = prompt('Please choose another number...'); secondNumber = parseFloat(secondNumber);
// 6. Create a new variable -- message -- which you'll use to build // a complete message to print to the document // Start by creating a string that includes <h1> tags as well // and the two input numbers. The string should look something like this: // "<h1>Math with the numbers 3 and 4</h1>" where the two numbers are // the values input from the user. Use string concatenation to create this // and make sure you actually perform the math on the values by // using the + symbol to add their values together var message = "<h1>Math with the numbers " firstNumber + " and " + secondNumber + </h1>" there's more but I wanna try and figure it out
document.write(message);
The screen is white and nothing appears...nothing. The error I get is in the var message line. Am I missing something? What am I doing wrong?
Thanks kindly,
Shari
2 Answers
Steven Parker
243,318 PointsIt's hard to tell in unformatted code, but it looks like the line where "message" is created is missing a "+" symbol before "firstNumber" and missing a quote mark before the closing tag.
For future questions, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area.
Or watch this video on code formatting.
Shari Staten
11,540 Pointsalert('Ready for some math?');
var firstNumber =prompt('Choose a number.');
firstNumber =parseInt(firstNumber);
var secondNumber = prompt('Choose one more number!');
secondNumber =parseInt(secondNumber);
var message = "<h1>Math with the numbers " + firstNumber + " and " + secondNumber + "</h1>";
message += firstNumber " + " secondNumber " = " (firstNumber + secondNumber);
It worked beautifully!!! Thank you! Forgive the delay. I took a breather before returning to the exercise.