Last active
June 4, 2019 06:32
-
-
Save singhkumarhemant/8d0482b48f7464e924caba24268fe0f8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 SPENDING_THRESHOLD = 200; | |
| const TAX_RATE = 0.08; | |
| const PHONE_PRICE = 99.99; | |
| const ACCESSORY_PRICE = 9.99; | |
| var bank_balance = 303.91; | |
| var amount = 0; | |
| function calculateTax(amount) { | |
| return amount * TAX_RATE; | |
| } | |
| function formatAmount(amount) { | |
| return "INR" + amount.toFixed( 2 ); | |
| } | |
| // keep buying phones while you still have money | |
| while (amount < bank_balance) { | |
| // buy a new phone! | |
| amount = amount + PHONE_PRICE; | |
| if (amount < SPENDING_THRESHOLD) { | |
| amount = amount + ACCESSORY_PRICE; | |
| } | |
| } | |
| amount = amount + calculateTax( amount ); | |
| console.log( | |
| "Your purchase: " + formatAmount( amount ) | |
| ); | |
| if (amount > bank_balance) { | |
| console.log( | |
| "You can't afford this purchase. :(" | |
| ); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Write a program to calculate the total price of your phone purchase.
You will keep purchasing phones until you
run out of money in your bank account. You’ll also buy accessories
for each phone as long as your purchase amount is below
your mental spending threshold.