JavaScript JavaScript Numbers Working with Numbers Numbers and Strings

Kevin Leong
Kevin Leong
1,652 Points

JavaScript numbers challenge task 1

For the first part of the task I came up with this cold however for some reason it doesn’t seem to work.

const width = '190px';
const totalImages = 10;

let totalWidth = totalImages * width; 

1 Answer

Martin Sole
Martin Sole
80,278 Points


You have the right idea, but you need to use parseInt(width) in your sum, so

 let totalWidth = totalImages * parseInt(width) ; 

At the moment in your example parseInt(width) isn't assigned to anything so the string value of width(190px) is still being used in the sum.