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 Doing Math

I don't get what I'm getting wrong

I don't get what I'm doing wrong any pointers.

script.js
var wholesalePrice = 5.45;
var retailPrice = 9.99;
var quantity = 47;
var salesTotal = retailPrice * quantity;
var profit = saleTotal - wholesalePrices * quantity ;
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="script.js"></script>
</body>
</html>

2 Answers

Cheryl Oliver
Cheryl Oliver
21,676 Points

You need to put brackets around wholesale and quantity. That is because you need to multiply wholesalePrice and quantity BEFORE you subtract. If you dont put brackets around it will subtract and then multiply.

var wholesalePrice = 5.45;

var retailPrice = 9.99;

var quantity = 47;

var salesTotal = retailPrice * quantity;

var profit = salesTotal - (wholesalePrice * quantity);

Steven Parker
Steven Parker
231,269 Points

Actually, the parentheses are not necessary.

Like most languages, JavaScript has rules for "operator precedence". Since multiplication (*) takes precedence over subtraction (-), it will be performed first even if it comes later in the expression.

But with that said, it can also be good practice to use parentheses just to make your intentions clear, or to make a complicated expression more readable, even when they are not necessary to get the correct result.

See this MDN page for more information on operator precedence.

Steven Parker
Steven Parker
231,269 Points

You have a couple of spelling errors:

  • you wrote "saleTotal" (singular) instead of "salesTotal"
  • you wrote "wholesalePrices" (plural) instead of "wholesalePrice"