Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Working With Numbers Numbers and Strings

Math challenge is not Working!

Hello

In the math challenge section, I wrote the code correctly as below:

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;

But I am not passing the test as the computer showing the code I wrote is not correct.

Please help.

Bruno Areias
Bruno Areias
4,776 Points

Hi, never done the challenge you're on. I would guess they are asking you to calculate the sales, profit and profitperUnit based on the above variables.

So I would guess the correct answer to be something like:

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

In that way if you change any of the variables wholesalePrice, retailPrice or quantity the script will still work correctly.

3 Answers

Tanja Schmidt
Tanja Schmidt
11,798 Points

Hi, I can't find the challenge you are referring to right now, but my guess is that you need to switch the absolute values with the variables in your calculations. The whole point of your first variables is to make life easier if a value changes for some reason, e.g. the retailPrice drops from 9.99 to 6.99: If you use the variable retailPrice and not the absolute number, you only need to change the value once and the rest will follow automatically.

For example:

var salesTotal = retailPrice * quantity;

... and so on!

Bruno Areias
Bruno Areias
4,776 Points

(LOL, posted the answer as a comment :/ )

Hi, never done the challenge you're on. I would guess they are asking you to calculate the sales, profit and profitperUnit based on the above variables.

So I would guess the correct answer to be something like:

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

In that way if you change any of the variables wholesalePrice, retailPrice or quantity the script will still work correctly.

Thanks to you both. Its working on. Have a great day.