Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Foundations Numbers Parsing Numbers From Strings

What am I doing wrong?!?


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

and it says that is wrong. I've typed different variations of this.

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

what am I doing wrong?

<!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("640", 10);

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

2 Answers

kevin jordan
kevin jordan
11,353 Points

Hey Erik -

Super close I think. All you need is to remove the parenthesizes around boxWidth in your parseInt call:

  var numWidth = parseInt("640", 10); => should be parseInt(boxWidth, 10);

Thank You!!!

William Li
William Li
Courses Plus Student 26,865 Points

you should pass in boxWidth as argument, not the number.

var numWidth = parseInt(boxWidth, 10);