Last active
June 4, 2019 06:32
-
-
Save singhkumarhemant/8d0482b48f7464e924caba24268fe0f8 to your computer and use it in GitHub Desktop.
Revisions
-
singhkumarhemant revised this gist
Jun 4, 2019 . No changes.There are no files selected for viewing
-
singhkumarhemant revised this gist
Jun 4, 2019 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -11,29 +11,25 @@ function calculateTax(amount) { } 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. :(" -
singhkumarhemant created this gist
Jun 4, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ 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 "$" + amount.toFixed( 2 ); } // keep buying phones while you still have money while (amount < bank_balance) { // buy a new phone! amount = amount + PHONE_PRICE; // can we afford the accessory? if (amount < SPENDING_THRESHOLD) { amount = amount + ACCESSORY_PRICE; } } // don't forget to pay the government, too amount = amount + calculateTax( amount ); console.log( "Your purchase: " + formatAmount( amount ) ); // Your purchase: $334.76 // can you actually afford this purchase? if (amount > bank_balance) { console.log( "You can't afford this purchase. :(" ); }