Skip to content

Instantly share code, notes, and snippets.

@YoneMoreno
Created November 1, 2017 07:36
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 YoneMoreno/12154f6853522feb9f6d75df4d6bf7bb to your computer and use it in GitHub Desktop.
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
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