Skip to content

Instantly share code, notes, and snippets.

@CraigRodrigues
Created October 6, 2016 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CraigRodrigues/8478f3d195685a57e84d9c8622ded47e to your computer and use it in GitHub Desktop.
Save CraigRodrigues/8478f3d195685a57e84d9c8622ded47e to your computer and use it in GitHub Desktop.
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
Copy link
Author

My function kinda sucks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment