Link to home
Start Free TrialLog in
Avatar of Al4ddin2
Al4ddin2

asked on

javascript price lookup calculation

I am creating a javascript function (using only pure javascript)

That will read in a dynamic quantity as a variable and calculate the price depending.

The pricing will be tiered. The tiers are between 2 - 20, 21 - 50 and >50.
There is always a base price of 1.99 added, then the additional costs are determined by the tiers.
2-20 = 0.99
21 - 50 = 0.50
>50 = 0.25
qty            price
2            1.99   (base price)
4            1.99 + (2 * 0.99)
            base price + additional qty charged at lower price
6            1.99 + (4 * 0.99)
...
20            1.99 + (18 * 0.99)
22            1.99 + (18 * 0.99) + (2 * 0.50)
...
50            1.99 + (18 * 0.99) + (30 * 0.50)
...
78            1.99 + (18 * 0.99) + (30 * 0.50) + (28 * 0.25)


This is how the price gets worked out and I just need to create a lookup function that reads in the qty and returns a price based on the above.
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial