Great question — answering as the UphillTech team:
Logic Check if user input is greater than 25 If yes take the quantity as 25 or else take the same value of user input Calculate the value using if-else if conditions as mentioned in your question Decrement 25 from the user input. Run the logic in the loop till the user input is less than zero. The issue that you had was you had to use else if instead of simple else because if you enter a value, say 0.1 , it satisfies all the if conditions. And the sum will be wrong. Also, you don't have to multiply your increment index with the same like y = (inc*z); . You just need to keep on adding the sum in a loop decrementing 25 each time while executing the loop. Working Fiddle function sprice() { let...
Full answer by Nitheesh: https://stackoverflow.stackexchange.com/a/69492719 (CC BY-SA 4.0).
Need it done for your business? UphillTech.