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 Numbers Working with Numbers Numbers and Strings

Gavin Lefleur
seal-mask
.a{fill-rule:evenodd;}techdegree
Gavin Lefleur
Full Stack JavaScript Techdegree Student 742 Points

Can 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);

script.js
const width = '190px';
const totalImages = 10;
const totalWidth = width x totalWidth;
const multiples = parseInt = (width);



//const numOfApples = parseInt(apples); // n
Michael Parente
seal-mask
.a{fill-rule:evenodd;}techdegree
Michael Parente
Full Stack JavaScript Techdegree Student 1,538 Points

Why does this not work? It gives me the correct answer?

const width = '190px';

const totalImages = 10;

const totalWidth = parseFloat(width) * totalImages;

console.log(totalWidth)

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?

const width = '190px';
const totalImages = 10;
const totalWidth = parseInt(width) * totalImages;
console.log(totalWidth)

3 Answers

The 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;.

Zaal Rottunda
seal-mask
.a{fill-rule:evenodd;}techdegree
Zaal Rottunda
Full Stack JavaScript Techdegree Student 1,796 Points

I'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;