Created
January 29, 2019 20:42
-
-
Save JPGITHUB1519/32d3b079c5417aa40b13740b7a90bb09 to your computer and use it in GitHub Desktop.
Introduction to JavaScript Programming Course from Front-End Master. https://frontendmasters.com/courses/javascript-basics/
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
/* Exercise from https://github.com/getify/You-Dont-Know-JS/blob/master/up%20&%20going/ch1.md#practice */ | |
(function() { | |
const TAX_RATE = 0.08; | |
const PHONE_PRICE = 99.99; | |
const ACCESORY_PRICE = 9.99; | |
const SPENDING_THRESHOLD = 200; | |
var accountBalance = 303.91; | |
var amount = 0; | |
function calculateTax(amount, taxRate) { | |
return amount * taxRate; | |
} | |
function numberFormat(number) { | |
return "$" + number.toFixed(2); | |
} | |
while (amount < accountBalance) { | |
amount += PHONE_PRICE; | |
if (amount < SPENDING_THRESHOLD) { | |
amount += ACCESORY_PRICE; | |
} | |
} | |
amount += calculateTax(amount, TAX_RATE); | |
console.log("Calculated Purchase: " + numberFormat(amount)); | |
if (amount <= accountBalance) { | |
console.log("You can afford it!"); | |
} else { | |
console.log("You cannot afford it!"); | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment