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

I don't get this. Creating the variable "profit" in task 2 seems to ruin task 1. Bug, or error from my side?

I tried commenting out line 15, which made task 1 pass again. Got new error, saying that I did not create a variable "profit". Created a variable named profit, without assigning anything to it, and then task 1 failed again.

script.js
var wholeSalePrice = 5.45;
var retailPrice = 9.99;
var quantity = 47;

/* Challenge Task 1 of 3
Create a new variable salesTotal that contains the total of the retailPrice multiplied by the quantity variable.*/

var salesTotal = retailPrice * quantity;

/* Challenge Task 2 of 3
Create another variable named profit. It should hold the value of the salesTotal variable minus the wholesalePrice 
multiplied by the quantity. In other words, if you sold 47 items for 9.99 but only paid 5.45 for each item, how much 
money did you make? */

var profit = salesTotal - wholeSalePrice * quantity;

// Oops! It looks like Task 1 is no longer passing. Why?? This exact code passes Task 1...
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>

5 Answers

my answer is absolutely correct but I keep getting this warning, very annoying it is wasting too much time. Oops! It looks like Task 2 is no longer passing.

Ivan Marchenko
Ivan Marchenko
8,962 Points

try this var profit = (salesTotal - wholeSalePrice) * quantity;

this should do the trick, I think.

The problem I'm experiencing, is that just declaring the profit variable breaks the answer to task 1. The variable totalSales holds the the sum of all sales combined, and to find the profit we need to subtract the value of (wholeSalePrice * quantity). At least, that's how I understand the task. I suspect a bug here, but I'll try some other solutions, including the one you suggest :)

Thanks for pointing me to that thread! :) It seems quite odd, I experienced the exact same problem as described there, and I am 100% sure I didn't change the variable name. I smell some sneaky bug here, and I'm trying to recreate it so that I can figure it out :)

Justice Omorodion
PLUS
Justice Omorodion
Courses Plus Student 8,315 Points

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

Irina Jerikalina
Irina Jerikalina
9,240 Points

Works var profit = salesTotal - (wholesalePrice * quantity);

Anastasia Aubrey
Anastasia Aubrey
780 Points

This one was weird, I tried this way a few times and it was still giving me the Oops error. Tired it again and it worked, here's what I got;

var wholesalePrice = 5.45; var retailPrice = 9.99; var quantity = 47; var salesTotal = retailPrice * quantity; var profit = salesTotal - (wholesalePrice * quantity);