Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
YDKJS - Up & Going - Challenge #1
var bankAccount = prompt("How much money is in your bank account?");
var spendingLimit = prompt("What is the max amount mof money do you wish to spend?")
var phonePrice = 100, accessoryPrice = 20, taxRate = 0.06, cost = 0;
function finalCheckout(amt) {
amt = amt + (amt * taxRate);
if (amt < bankAccount)
console.log("You can afford this!");
else
console.log("Unfortunately you cannot afford this. :(");
amt = "$" + amt.toFixed(2);
console.log("Your total is: " + amt);
}
// A loop to run until you cannot buy any more iPhones
while (spendingLimit>= phonePrice) {
cost += phonePrice;
spendingLimit -= phonePrice;
}
// Once out of phones, time to spend the rest on accessories
while (spendingLimit >= accessoryPrice) {
cost += accessoryPrice;
spendingLimit -= accessoryPrice;
}
finalCheckout(cost);
@CraigRodrigues

This comment has been minimized.

Copy link
Owner Author

commented Oct 6, 2016

My function kinda sucks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.