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 trialGavin Lefleur
Full Stack JavaScript Techdegree Student 742 PointsCan anyone help? Imagine you have 10 images on a web page. Each image is 190 pixels wide. Using the two variables
const width = '190px'; const totalImages = 10; const totalWidth = width x totalWidth; const = parseInt = (width);
const width = '190px';
const totalImages = 10;
const totalWidth = width x totalWidth;
const multiples = parseInt = (width);
//const numOfApples = parseInt(apples); // n
3 Answers
jb30
44,807 PointsThe letter x
is not used for multiplication in JavaScript. Instead, use the *
sign. You will also need to convert width
to an integer value before multiplying it.
As in the commented out line you have at the end, parseInt
should not have an =
sign between it and the opening parenthesis, so const multiples = parseInt = (width);
would become const multiples = parseInt(width);
. You could then multiply multiples
and totalWidth
by using the *
sign: const totalWidth = multiples * totalWidth;
.
Gavin Lefleur
Full Stack JavaScript Techdegree Student 742 PointsThankyou JB, I have a lot to learn. appreciate it
Zaal Rottunda
Full Stack JavaScript Techdegree Student 1,796 PointsI'm using the same code but getting an error that 'Are you assigning 'totalWidth' the correct math operation?"
this is my code: const width = '190px'; const totalImages = 10; const totalWidth = typeof parseInt(width) * totalImages;
Michael Parente
Full Stack JavaScript Techdegree Student 1,538 PointsMichael Parente
Full Stack JavaScript Techdegree Student 1,538 PointsWhy does this not work? It gives me the correct answer?
go ahead and console.log it for yourself. You will see the answer is 1900. Which is 190 x 10. Yet the system keeps saying I am wrong. Please help me understand why it is wrong. I have only been doing this for a couple months, so I am sure there is some kind of rule I am breaking for the system to say it is incorrect. Thank You!
Nevermind I switched it too the below and it passed. I am still curious why the above doesnt pass if anyone knows?