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 Basics (Retired) Working With Numbers Numbers and Strings

Andre Chavira
seal-mask
.a{fill-rule:evenodd;}techdegree
Andre Chavira
Front End Web Development Techdegree Student 4,556 Points

Am i suppose to retrieve it in a prior var or withing the total var?? i tried both parsefloat(width) and parseln(width).

I also tried using parsefloat('190px') and parseln('190px') by making a prior var to set the with var ready to use in the last var on the page. I'm honestly a bit confused, could somebody please give me a hand?

app.js
var width = '190px';
var numOfDivs = 10;
var width = parselnt('190px');
var totalWidth = width * numOfDivs; 
index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>

1 Answer

Dave StSomeWhere
Dave StSomeWhere
19,870 Points

I think that this challenge's goal is to reinforce that parseInt() will return the integer portion of a string if it is at the beginning of the string like the '190px'.

Try something like

var width = '190px';
var numOfDivs = 10;
var totalWidth = parseInt(width) * numOfDivs; 

FYI - The browser console is your friend. MDN parseInt()

Andre Chavira
seal-mask
.a{fill-rule:evenodd;}techdegree
Andre Chavira
Front End Web Development Techdegree Student 4,556 Points

Thank you yes i had tried that but i would still get an error alert, however i managed to get it to work by adding the parseInt to the numOfDivs aswell, i didnt think i needed to do that because it wasn't specified in the instructions but it worked which surprised me.