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 Introducing the Practice

Code does not work.

I have understood the instructions but code does not work! I have written the same code of the professor! In the js file: alert("Let's do some math!"); var firstNumber = prompt("Enter a number: "); firstNumber = parseFloat(firstNumber); var secondNumber = prompt("Enter a number: "); secondNumber = parseFloat(secondNumber); var message = "<h1>Math with the numbers " + firstNumber + " and " + secondNumber + "</h1>"; document.write(message);

In the html file: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Practice JavaScript Math</title> <link href="css/styles.css" rel="stylesheet"> </head> <body> <script src="js/math.js></script> </body> </html>

Can you post your code?

Kevin Gates
Kevin Gates
15,053 Points

Next time, please use the Markdown cheatsheet to make your code more readable, like this:

JS File

alert("Let's do some math!");
var firstNumber = prompt("Enter a number: ");
firstNumber = parseFloat(firstNumber);
var secondNumber = prompt("Enter a number: ");
secondNumber = parseFloat(secondNumber);
var message = "<h1>Math with the numbers " + firstNumber + " and " + secondNumber + "</h1>";
document.write(message);

HTML File

 <!DOCTYPE html>
 <html lang="en">
  <head>
   <meta charset="UTF-8">
   <title>Practice JavaScript Math</title>
   <link href="css/styles.css" rel="stylesheet">
  </head>
  <body>
   <script src="js/math.js></script>
  </body>
</html>

2 Answers

I posted my code. I want check if my code works first, then I'll add the rest of the code to complete the challenge.

It works, there was a problem in html file. I have re written the script in the html file. That's weird!

You are missing a closing quote here:

<script src="js/math.js>

in your html. Should be

<script src="js/math.js">

Where? I put the closing quote, it's an error of workplace, it does not work well.