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

Code Challenge: Numbers

Task: A variable named "boxWidth" already exists with a value of "640px". Create a new variable named "numWidth" and use the "parseInt" method to extract the numeric value from boxWidth's string value.

I tried creating the "var numWidth = parseInt()" but I went wrong somewhere, I'm sure. Can anyone help?

Lost here!

<!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";



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

3 Answers

Answered my own question...use var numWidth = parseInt(boxWidth, 10); if you are stumped too :)

Hi Kyle,

I've done again the code challenge, it worked fine. You pasted the code from the challenge, but without your code. May you give us your try, so we can point what you did wrong (sometimes it is just a missing closing bracket, or something like that). Waiting for your reply :).

sorry...meant to say that I answered my own question and that's how it worked. All good!