repl.it
@MNouri/

BuyPhone

Nodejs

No description

fork
loading
Files
  • index.js
index.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
//This program will keep buying phones and accessories according to how much willing to spend untill ran out of money or reached the limit. It also calculates tax and gives a total in the end.


const SPENDING_THRESHOLD = 400;
const PHONE_PRICE = 99.99;
const ACCESSORY_PRICE = 9.99;

var bank_balance = 406.91;
var subTotal = 0;
var tax = 0;
var total = 0;

var phones = 0;
var accessories = 0;

while (bank_balance >= SPENDING_THRESHOLD){
  phones++;
  accessories++;

  //total += phones * PHONE_PRICE + accessories * ACCESSORY_PRICE;

  bank_balance -= phones * PHONE_PRICE + accessories * ACCESSORY_PRICE;

  subTotal += phones * PHONE_PRICE + accessories * ACCESSORY_PRICE;

  tax = 0.08 * bank_balance;

  total += phones * PHONE_PRICE + accessories * ACCESSORY_PRICE + tax;
}

if (phones > 0){
  console.log("Here is your receipt:")
  console.log("")
  console.log("You have " + phones + " phone(s)," + accessories + " accessories");
  console.log("Subtotal: " + subTotal);
  console.log("Tax: " + tax);
  console.log("Total: " + total);
}
else {
  console.log("You do not have enough money")
}