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
Dwayne Sauls
1,279 PointsHaving trouble with variables
I do not understand the difference between these variables.Can somebody please elaborate for me?
var departmentName = ''; var highestSale = 0; var lowestSale;
3 Answers
Coen van Campenhout
5,034 PointsHi Dwayne,
do you have some context for the question? The ony answer I could give you right now is that
departmentName is an empty string as departmentName = "" indicates and highestSale is an integer
something that could also be giving you issues is the fact that yoy are not closing your quotes in departmentName try it like this: var departmentName = "";
Dwayne Sauls
1,279 PointsHi Jason Anello Coen van Campenhout I have attached the following below: As an example one of the variables that has a value of zero I don't understand why.
////////////////////
var mostProfitableDay = function(database)
{
var mondayTotalSales = 0;
var tuesdayTotalSales = 0;
var wednesdayTotalSales = 0;
var thursdayTotalSales = 0;
var fridayTotalSales = 0;
for(var s = 0; s < database.length; s++)
{
if(database[s].day === 'Monday')
{
mondayTotalSales += database[s].sales;
}
if(database[s].day === 'Tuesday')
{
tuesdayTotalSales += database[s].sales;
}
if(database[s].day === 'Wednesday')
{
wednesdayTotalSales += database[s].sales;
}
if(database[s].day === 'Thursday')
{
thursdayTotalSales += database[s].sales;
}
if(database[s].day === 'Friday')
{
fridayTotalSales += database[s].sales;
}
}
if(mondayTotalSales > (tuesdayTotalSales && wednesdayTotalSales && thursdayTotalSales && fridayTotalSales))
{
return "Monday was the most profitable day.";
}
else if(tuesdayTotalSales > (mondayTotalSales && wednesdayTotalSales && thursdayTotalSales && fridayTotalSales))
{
return "Tuesday was the most profitable day.";
}
else if(wednesdayTotalSales > (mondayTotalSales && tuesdayTotalSales && thursdayTotalSales && fridayTotalSales))
{
return "Wednesday was the most profitable day.";
}
else if(thursdayTotalSales > (mondayTotalSales && tuesdayTotalSales && wednesdayTotalSales && fridayTotalSales))
{
return "Thursday was the most profitable day.";
}
else
{
return "Friday was the most profitable day.";
}
}
///////////////////
Jason Anello
Courses Plus Student 94,610 Pointsfixed code formatting
This link will show you how to post code: https://teamtreehouse.com/forum/posting-code-to-the-forum
Jason Anello
Courses Plus Student 94,610 PointsHi Dwayne,
Those variables at the top are initialized to 0 because they're being used to calculate a total sum.
You start at zero and then you continually add more numbers to that giving you a total sum at the end.
This is a common pattern when you're calculating a running total. https://en.wikipedia.org/wiki/Running_total
Also, I don't think the logic in the last part is going to work the way you're intending. The logical AND comparsions are going to return the last sales value if all sales are greater than 0.
If there are any days where sales was 0 then the entire expression evaluates to 0.
This is going to lead to incorrect comparisons.
Let me know if you need help on going in a different direction there.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi Coen,
It was single quotes there so it's ok.
I agree that some context to the question would be helpful.