Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to give 10% discount for the total price above 200 in shopping cart. I had given following code but it is not working. Pl. give me proper code.

What I have tried:

},
     getDiscountPrice: function(products, totalPrice, totalQuantity) {
       var x = 200
     if (totalPrice > x) {
       DiscountPrice = totalPrice - (totalPrice * .10)
     }
     return totalPrice > x;

       console.log("calculating discount" totalPrice > x);

     }
Posted
Updated 4-Nov-19 1:03am
Comments
F-ES Sitecore 4-Nov-19 7:21am    
You need to actually take time to learn and understand javascript. If you're just asking for code on forums and pasting it into your coursework without understanding it then you're not learning anything.

1 solution

JavaScript
return totalPrice > x;

That returns a boolean value of true or false, and the calculated DiscountPrice value is thrown away after it is calculated. Also, why are you passing in products and totalQuantity since you do not use either value anywhere in your calculation.

Think about the simple steps needed to do this:
the function only needs to know the current total price, and the steps are something like:
1. set newprice = totalprice.
2. if totalprice > x then set newprice = totalprice * .90
3. return newprice // if totalprice is less than x, then original total will be returned
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900