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 trialAlonzo Delk
6,991 PointsDo I multiply by the totalWidth? Or do I add another variable with the purseInt stating the amount?
const width = '190px';
const totalImages = 10;
const totalWidth = width * totalImages;
const num = 1900;
const webValue = parseInt(1900);
1 Answer
Peter Vann
36,427 PointsHi Alonzo!
Your goal is to multiply the width by totalImages.
width, however, is a CSS string property value, so for the math to work properly you have to cast/convert width to a number ( using parseInt() ).
So the code is actually this simple (and passes)
const width = '190px';
const totalImages = 10;
const totalWidth = parseInt(width) * totalImages;
Note: parseInt, in this case, casts/converts '190px' to 190, thus after the multiplication, totalWidth will be 1900.
(190 * 10) == 1900, in other words...
BTW, if you really want to see it, open your devtools and find the console.
At the prompt type:
> const width = '190px';
And hit enter. It will return undefined, which is fine.
The type:
> console.log( parseInt(width) );
It will return:
190
undefined
You can ignore the undefineds (undefined is the return value of console.log() regardless of what it logs)
(If you type 2 + 2 at the prompt it will return 4, not undefined).
More info:
I hope that helps.
Stay safe and happy coding!