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

Math in Java

Create one last variable name profitPerUnit. In that variable store the amount of profit you made for each unit. You can calculate this by dividing the profit by the quantity.

Can anyone please help me out and let me know what i'm missing here??

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

3 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

use parentheses and your variable names, right now the order of operations is not going to give the result you want. you want to divide profit by 47 but right now the only part being divided by 47 is the part after the minus sign, giving the wrong result. actually the whole point of this is to use the variable names, not to put the numbers over and over again. the previous tasks should utilize the variables, not the numbers themselves.

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

the variable names do not go in quotes. just type them out. as for usage, for example if quantity = 5 and profit per unit = 8, you should calculate total profit as quantity X profit per unit, not 5 X 8. or if we had a class of 30 kids and 180 candies, we should arrive at candies per kid with candies/kids, not 180/30. that's what they are teaching here. then if say a new kid arrives in class, you just update the kid variable from 30 to 31, and it will propagate through your program and you won't have to find every 30 and change it to 31 manually. using () in math is just to control the order of operations from the basic rules. in your code above you have 9.99 * 47 - 5.45 * 47/47. the order of operations is mult and div, then add and subtract, left to right. so in this line, what is happening that gives the wrong result is that 9.99 is mult by 47, and 5.45 is mult by 47, and then just that second part is divided by 47. well you just mult 5.45 by 47, then you divided by 47, that did nothing! so the 9.99 X 47 is only having 5.45 subtracted from it, giving a wrong answer. if instead you had (9.99 X 47 - 5.45 X 47) / 47, that's what is intended math-wise. this calculates the revenue, subtracts the costs, THEN divides by units to get profit per unit. when i did the challenge i used the variable names and () in this manner to pass, that's what they want you to do here.

Could you give me an example of where I would use the parentheses and variable names. Ive tried using the variable names in quotations and I keep receiving a error message! Thanks