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

david mchale
david mchale
1,434 Points

Total Width ParseInt() issue

Getting a Parse error in my function in the console but the parse function syntax looks right to me....

app.js
function myTotal(){

  var width = '190px';
  var numOfDivs = 10;
  var totalWidth = parseInt(width) x numOfDivs;
  return totalWidth;
};

var result = myTotal();
document.write(result);
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

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey David,

First... you have way too much code. For this challenge, the instruction only say to =>

create a new variable named totalWidth that multiplies the width by the numOfDivs variable.

That's it. So, while you're code may be correct (except for one error I will get to), it is not what the instructions want you to do. Challenges are very picky... The general rule is that if the instructions didn't tell you to do it... don't.

So, the one line of code you do need for the task is there, but there is also an error in that line. The multiply symbol is the asterisk (*) not the lower-cased 'x'. So once you fix that up and delete all the other lines of code, you're left with:

var width = '190px';
var numOfDivs = 10;
var totalWidth = parseInt(width) * numOfDivs;

Hope that helps. And remember how specific the challenges are. If you don't follow the instructions exactly, you more often than not will receive the Bummer! even if the code is syntactically correct.

Keep Coding! :) :dizzy:

david mchale
david mchale
1,434 Points

It did say put it into a function, which i have to admit was a little odd since it hadnt been covered yet.. thanks for your quick response jason! much appreciate it :)

...and yes! i am a tit for using the x instead of *. Typical Monday morning error!

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Still Sunday night here. Lol.

The only reference to "function" I see in the instructions is in the last sentence. This is actually just giving you a hint that you'll need to use JavaScript's parseInt() function to complete the Task. The wording sometimes get the best of us. :see_no_evil:

But for not being "taught yet," you got it spot on... Good job! :thumbsup: