Created
November 1, 2017 07:36
-
-
Save YoneMoreno/12154f6853522feb9f6d75df4d6bf7bb to your computer and use it in GitHub Desktop.
Doing the practice excercise in the first chapter of the book by Kyle called You Dont Know Javascript Going & Up
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
const taxRate = 0.07; | |
const phonePrice = Number(prompt("What is the price for the phone you are looking for?")); | |
const accessoryPrice = Number(prompt("How much bucks does the accesory cost?")); | |
const spendingThreshold = 200; | |
var accountBalance = Number(prompt("How much IS YOUR BANK ACCOUNT?")); | |
function calculateTax(purchasePrice){ | |
return purchasePrice + purchasePrice*taxRate; | |
} | |
function formatPrice(priceToBeFormatted){ | |
return priceToBeFormatted.toFixed(2) + "$"; | |
} | |
while(accountBalance>0){ | |
var thisPurchasePrice = phonePrice + accessoryPrice; | |
console.log("You are going to buy expending: " + formatPrice(calculateTax(thisPurchasePrice)) ); | |
if(accountBalance>calculateTax(thisPurchasePrice)){ | |
accountBalance -= calculateTax(thisPurchasePrice); | |
}else{ | |
break; | |
} | |
console.log("Your account is now: " + accountBalance); | |
} | |
console.log("You have finished buying"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment