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 Foundations Numbers Operators

Numbers - code not working

I have absolutely no clue why this code isn't working, and I started adding lots of parentheses just in case, but still it didn't work...Help!

  var three = (a + b);
  var ten = (a + c) * b;
  var nineteen = ((c*c) + a + b);
  var onehundred = ((c**c)**c) + (b**c) + (c * (c+a));

2 Answers

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

The problem is this line of code:

var onehundred = ((c**c)**c) + (b**c) + (c * (c+a));

There's no ** operator in JavaScript. To raise a number to the power of another number you use the Math.pow() method. So to get c^b you'd write this Math.pow(c,b)

The challenge is asking for you to use common numeric operators -- + - * / % -- anyway so skip the Math.pow() method.

I see! That's odd that there isn't an operator for exponents. Thanks Dave!

Try this (not sure what the a,b,c represents so will use 1 2 3) you will need to change to letters

    var three = 1 + 2
    var ten = (2 + 2 + 1) * 2
    var nineteen = (3 * 3) + (2 + 2 + 2 + 2 + 2)
    etc

Just remember that things in parentheses are evaluated first.

I see! I didn't realize that there isn't an operator for exponents. Thanks Adam!