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

Nazaam Kutisha
Nazaam Kutisha
7,667 Points

I Need Help with this challenge.

My response was:

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

My answer isn't accepted by code engine.

```<!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>```

4 Answers

Adam Moore
Adam Moore
21,956 Points

This particular challenge is asking you to use the variable boxWidth that has the value of "640px" for the parseInt() method, not simply manually writing in the "640px" into the parseInt() method. So, var numWidth = parseInt(boxWidth, 10) would work.

Ryan Drake
Ryan Drake
12,587 Points

I assume you want to change numWidth to boxWidth? The parseInt will work as intended.

Nazaam Kutisha
Nazaam Kutisha
7,667 Points

Its a string, the challenge asks you to use parseInt to extract the integer from the string.

Nazaam Kutisha
Nazaam Kutisha
7,667 Points

Good it worked. I tried it that way first, but used "" around the boxWidth variable so it wasn't passing.

Adam Moore
Adam Moore
21,956 Points

Awesome! Glad I could help!