protoship/rescript-tutorial

Rewrite exercise 1 in chapter 2

Closed this issue · 5 comments

-----------------------------------------------------------------------------
Exercise 1
-----------------------------------------------------------------------------
Calculate the discount applicable to shopping cart total amount using the
following rules:
1. When the total is either 500 or above:
- a flat 10% discount.
2. When the total is either 200 or above, but below 500:
- add 25 to,
- a 5% discount on the amount greater than 200
-----------------------------------------------------------------------------

Rewrite the exercise copy to improve readability & comprehension.

The part where the 5% discount has to be applied has issues. It is easy to miss out on the fact that the calculation involves deducting the cart total amount from 200, before applying a 5% discount.

@jcsherin
Also, what is "add 25 to, " on line 43 suppose to mean?

@ForgottenProgramme When the value is 200 >= & <500

discount = (value - 200 * 0.05) + 25

So for 499
discount = ( 499 - 200 * 0.05 ) + 25 = 39

  1. When the total is either 200 or above, but below 500:
    • add 25 to,
    • a 5% discount on the amount greater than 200

I think, we can change this to:

  1. When the total is either 200 or above, but below 500:
  • 5% discount on the amount greater than 200, plus 25. That is, discount = (total-200) * 0.05 + 25 .

@ForgottenProgramme I've made a draft-PR. Please take a look and see if any other changes are required.