Silly phone buying app...
"use strict"; | |
const SALESTAX = .0975, | |
PHONE_PRICE = 200.00, | |
ACCESS_PRICE = 40.00; | |
var ba = prompt("How much money you got?"), | |
ac = prompt("When to stop buying accessories?"), | |
bankAccount = parseInt(ba), | |
accessoryLimit = parseInt(ac), | |
subTotal, | |
totalCost; | |
function salesTx(subtotal) { | |
subTotal = subTotal + (subTotal * SALESTAX); | |
return subTotal; | |
} | |
function phoneAndAccessory() { | |
subTotal = PHONE_PRICE + ACCESS_PRICE; | |
totalCost = salesTx(subTotal); | |
totalCost = parseInt(totalCost); | |
console.log("Price of phone and accessory with sales tax: " + "$" + totalCost.toFixed(2)); | |
return totalCost; | |
} | |
function justPhone() { | |
subTotal = PHONE_PRICE; | |
totalCost = salesTx(subTotal); | |
totalCost = parseInt(totalCost); | |
console.log("Price of just phone with tax: " + "$" + totalCost.toFixed(2)); | |
return totalCost; | |
} | |
function buySomeStuff() { | |
do { | |
if (bankAccount > accessoryLimit) { | |
phoneAndAccessory(); | |
bankAccount = (bankAccount - totalCost).toFixed(2); | |
console.log("Phone and Accessory purchased, bank account balance: " + "$" + bankAccount); | |
bankAccount = parseInt(bankAccount); | |
} else if (bankAccount < accessoryLimit && bankAccount >= totalCost) { | |
justPhone(); | |
bankAccount = (bankAccount - totalCost).toFixed(2); | |
console.log("Just a phone purchased, bank account balance: " + "$" + bankAccount); | |
bankAccount = parseInt(bankAccount); | |
} | |
} while (bankAccount > totalCost) | |
if (bankAccount <= totalCost) { | |
console.log("Insufficient funds: " + "$" + bankAccount.toFixed(2)); | |
} | |
} | |
buySomeStuff(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment