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

how do you multiply variables?

im stuck.

app.js
var width = '190px';
var numOfDivs = 10;
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>

2 Answers

Hey Vittorio,

Remember the parseInt command? All you have to do is pass in that width variable to parseInt and it will grab the number (integer) value from the variable and then you can multiply it by numOfDivs which is already a number and store that value in the totalWidth variable.

var width = '190px';
var numOfDivs = 10;
var totalWidth = parseInt(width) * numOfDivs;
Michael Hess
Michael Hess
24,512 Points

Hi Vittorio,

In this challenge we need to use the parseInt() method. Create a variable named totalWidth, then multiply width by numOfDivs. The parseInt() method will convert the string into an integer. Please see the following code:

var width = '190px';
var numOfDivs = 10;

var totalWidth = parseInt(width) * numOfDivs;

If you have any questions I'll be more than happy to answer them! Hope this helps!