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

var profitPerUnit = 213.38 / 47:

it keeps asking me if i use / symbol?

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

4 Answers

var profitPerUnit = 213.38 / 47;

Muhammad Ehsan Hanif
Muhammad Ehsan Hanif
8,236 Points

You don't have to do the math yourself.

Just put

var profitPerUnit = profit / quantity;

I assume you're on challenge 3 of 3? If so, the code checker shouldn't have let you passed the first two challenges. You should be using the variables in every expression, not the actual values. Variables are there to store the values for you, for future use.

Consider if the whole sale price changes. The way you've written your solutions, you'd have ton manually search for, and change the price everywhere you've written $5.45. That'd be even more tedious to do, if your wholesale and retail price were the same from the beginning. How would you know which represented which?

Your code should look like this:

var wholesalePrice = 5.45,
retailPrice = 9.99,
quantity = 47,
salesTotal = retailPrice * quantity,
profit = salesTotal - wholesalePrice * quantity,
profitPerUnit = profit / quantity;

With your program written like this, changing a value at the top will be reflected at the bottom. You make a change in one place, and it changes everywhere else. For example:

var wholesalePrice = 5.45,
retailPrice = 7.99, //retail price dropped by two dollars
quantity = 50, //quantity goes up by 3; anywhere you see "quantity, the value 50 is stored there
salesTotal = retailPrice * quantity, //this is now 7.99 * 50
profit = salesTotal - wholesalePrice * quantity, 
profitPerUnit = profit / quantity; 

Note: I'm not sure if you're familiar with the way I've written the variables. you can use a comma to separate multiple variable declarations, if they're all the same type. It does nothing but save a few keystrokes -- typing var multiple times.

Thanks...something so simple..:) Just love the treehouse help forum :)