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

No preview

I'm not getting any preview of my code https://w.trhou.se/qk7zhumo02

1 Answer

The first thing to check would be: Is the script file linked properly? It is.

So there must be something in the script that is causing an error. Here is where the console in developer tools can be extremely helpful. In the console the first error message you receive is:

Uncaught SyntaxError: Unexpected string    math.js:9

So check line 9

var message = "<p><h1>Math with the numbers" + number1 + " and " + number2" ".</p></h1>";

and you will see quotes where there was supposed to be concatenation

number2" ".</p></h1>";

should be

number2 + ".</p></h1>";

Fix this and refresh for a new error

Uncaught SyntaxError: Unexpected token <     math.js:11

So check line 11

message += <br>  number1 - number2

This should be string concatenation. Fix this

message += "<br>" + (number1 - number2)

and while we're at it might as well fix the other lines as well

message += "<br>" + (number1 + number2)
message += "<br>" + (number1 * number2)
message += "<br>" + (number1 / number2)

Now refresh and the alert pops up. Progress. But if you keep your eye on the console you'll soon find another error.

Keep repeating this process and working with the console and you should be able to debug your code.