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 trialKevin Fernandez-Gonzalez
16,790 PointsI don't get what I'm getting wrong
I don't get what I'm doing wrong any pointers.
var wholesalePrice = 5.45;
var retailPrice = 9.99;
var quantity = 47;
var salesTotal = retailPrice * quantity;
var profit = saleTotal - wholesalePrices * quantity ;
<!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
21,676 PointsYou 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
231,275 PointsYou have a couple of spelling errors:
- you wrote "saleTotal" (singular) instead of "salesTotal"
- you wrote "wholesalePrices" (plural) instead of "wholesalePrice"
Steven Parker
231,275 PointsSteven Parker
231,275 PointsActually, 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.