Created
October 6, 2016 12:19
-
-
Save CraigRodrigues/8478f3d195685a57e84d9c8622ded47e to your computer and use it in GitHub Desktop.
YDKJS - Up & Going - Challenge #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My function kinda sucks.