DEV Community

JEGADESHWARAN B
JEGADESHWARAN B

Posted on

Shopping Discount System

You have:
amount
isMember(boolean)

A user buys products worth amount.
if amount ≥ 5000 => 20% discount
if amount ≥ 2000 => 10% discount
therwise => no discount
members get extra 10% discount
Print final price after discount.

let amount=1000;
let isMember = false;
const MemberDiscount = 10;
let discount = 0;
if(amount>=5000){
 discount = 20;
  }
  elseif(amount>=2000){
  discount = 10;
  }
  else{
  if(isMember){
  console.log(amount - (amount*(discount+MemberDiscount)/100));
  }
  else{
  console.log(amount - ((amount*discount)/100));
  }
  }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)