Skip to content

Instantly share code, notes, and snippets.

@singhkumarhemant
Last active June 4, 2019 06:32
Show Gist options
  • Select an option

  • Save singhkumarhemant/8d0482b48f7464e924caba24268fe0f8 to your computer and use it in GitHub Desktop.

Select an option

Save singhkumarhemant/8d0482b48f7464e924caba24268fe0f8 to your computer and use it in GitHub Desktop.

Revisions

  1. singhkumarhemant revised this gist Jun 4, 2019. No changes.
  2. singhkumarhemant revised this gist Jun 4, 2019. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions YDNJS_UP_AND_GOING_example1
    Original file line number Diff line number Diff line change
    @@ -11,29 +11,25 @@ function calculateTax(amount) {
    }

    function formatAmount(amount) {
    return "$" + amount.toFixed( 2 );
    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;

    // 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. :("
  3. singhkumarhemant created this gist Jun 4, 2019.
    41 changes: 41 additions & 0 deletions YDNJS_UP_AND_GOING_example1
    Original 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. :("
    );
    }