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

Christina Araujo
seal-mask
.a{fill-rule:evenodd;}techdegree
Christina Araujo
Full Stack JavaScript Techdegree Student 4,819 Points

I am using the / symbol to divide profit by quantity, what is going on?

I am stuck here, however I am using the proper symbols, however I am still getting the error.

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

2 Answers

nico dev
nico dev
20,364 Points

Hi Christina Araujo ,

Your solution works, as long as the values for profit, quantity and the other values that they depend on do not change.

But remember this: variables can be assigned a variable, and then you can change that value. Let's suppose you use that code for your company you will probably use that variables every month and fiscal year with different variables, right? The big advantage of variables is you can reuse them.

So, having said that, how would you use that formula for every month, even if the values change? Well, instead of assigning the profit variable the number that results from the operation, you would assign it the operation itself with the variable names, regardless of their current value.

// So instead of:
var a = 1;
var b = 2;
var c = 1 + 2;
// c is, and will always be, 3, right?

//What about doing:
var a = 1;
var b = 2;
var c = a + b;
// Right now, c is also 3, but if next month you decide to change the a's value 5, 
// now c will automatically change (so to say it) to 7, right?
// Now, that's the power that variables give you in JS.
// And that's what this challenge want you to know. :)

Hope that clear things a bit, but otherwise, feel free to follow up here.