@mcuringa/

## No description

main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* A solution to the lemonade calculator
* lab problem.
* This program estimates
*/

/**
* print out a welcome message to start the program
*/
function welcome() {
console.log(`
--------------------------------------
Welcome to the lemonade estimator
--------------------------------------
`);
}

/**
* prompt the user for input according to `msg`
* and return the answer converted to a float
*/
function promptFloat(msg) {
let x = window.prompt(msg);
return Number.parseFloat(x);
}

/**
* Converts a float, `amt`, into
* a string with a dollar sign (\$)
* and returns the string.
*/
function money(amt) {
let dollars = "\$" + Number.parseFloat(amt).toFixed(2);
return dollars;
}

/**
* This function asks for all of
* expenses that go into selling
* 1 cup of lemonade.
*/
function getExpensePerCup() {
let msg = `
GATHERING EXPENSE DATA
Enter how much it costs you for one (1) of these items.
Click <OK> to continue.

`;

window.prompt(msg);
let cupCost = promptFloat("How much do you pay for 1 new cup?");
let lemonCost = promptFloat("How much do you pay  for 1 lemon?");

// for each cup of lemonade we need 1 cup and 3 lemons
return cupCost + lemonCost * 3;
}

/**
* prints profits and expenses given
* for a given quantity of lemonade sold
*/
function resultForQty(qty, cupPrice, cupCost) {

let cost = qty * cupCost;
let revenue = qty * cupPrice;
let profit = revenue - cost;

console.log();
console.log("if you sell " + qty + " cups of lemonade at " + money(cupPrice) + " per cup");
console.log("expenses: " + money(cost));
console.log("revenues: " + money(revenue));
console.log("  PROFIT: " + money(profit));
console.log("-------------------------");

}

/**
* Show the user expenses and profits at various levels of sales
*/
function showResults(cupCost, cupPrice) {

console.log();
console.log("------- DISPLAYING RESULTS -------");

resultForQty(20, cupPrice, cupCost);
resultForQty(50, cupPrice, cupCost);
resultForQty(100, cupPrice, cupCost);
resultForQty(500, cupPrice, cupCost);

}

/**
* start the program and control the flow
*/
function main() {

let cupCost = getExpensePerCup();
let cupPrice = promptFloat("How much do you charge for a cup of lemonade?");
showResults(cupCost, cupPrice);
}

main();
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie