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 Foundations Numbers Parsing Numbers From Strings

var numWidth = parseInt("640px",10); this is correct or I am missing something. I need a little help here.

I thought i did this right.

index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>JavaScript Foundations: Parsing Numbers From Strings</title>
    <link rel="stylesheet" href="core.css">
    <script>
      var boxWidth = "640px";
      var boxHeight = "480px";
      var numWidth = parseInt("640px",10);



    </script>
  </head>
  <body>
    <h1>JavaScript Foundations</h1>
    <h2>Parsing Numbers From Strings</h2>
    <script src="viewer.js"></script>
  </body>
</html>

3 Answers

Hugo Paz
Hugo Paz
15,622 Points

Hi Justin,

You are supposed to pass the variable to the method like so:

var numWidth = parseInt(boxWidth, 10);
Chris Shaw
Chris Shaw
26,676 Points

Hi Justin,

The error is occurring because you haven't give boxWidth as a parameter for parseInt, instead you've given a static string which the challenge isn't looking for.

var numWidth = parseInt(boxWidth, 10);

Happy coding!

Question. What does the "10" represent? I'm having trouble with JavaScrip myself or maybe I'm just slow when it comes to JS.

The challenge states "Similarly, a variable named "boxHeight" already exists with a value of "480px". Create a new variable named "numHeight" and use the "parseInt" method to extract the numeric value from boxHeight's string value."...

Where does the "10" fit into what the answer is?

Hugo Paz
Hugo Paz
15,622 Points

The number "10" is the radix parameter. It is used to specify which numeral system to be used, for example, a radix of 16 (hexadecimal) indicates that the number in the string should be parsed from a hexadecimal number to a decimal number.

In this case we want to parse it to a decimal number so we use '10'.