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

parse code

failing to extract numbers using the parse

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

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

2 Answers

Hey Prudence Khupe,

It wants you to use the variable instead of the actual value because a lot of times those variables will be dynamically generated by some other part of the program. So, instead of putting the value of boxWidth into parseInt, put the variable name like so:

      var boxWidth = "640px";
      var boxHeight = "480px";
      var numWidth = parseInt(boxWidth, 10);

This way if boxWidth were to change we would get the value of boxWidth. I hope that makes sense! :)

Hi Prudence,

Just swap out the number - "640px" to replace it with variable name boxWidth, we need to extract the number from the boxWidth's variable, not string or number.

  var numWidth = parseInt("640px", 10)

Hope that helps.