Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi at first i wanted to calculate total with quantity which i manage to do

then i wanted to create 1 quantity 500 and rest add 125 as quantity increase which was little complicated but somehow did it i know code written are not organize as perfect coder sorry about that

now i am stuck with new problem which is that i want to calculate 1st quantity 500 2nd qty add 125, 3rd qty add 125 and 4th qty add 125 but when increment goes above every 4th quantity 5th quantity should repeat equation like add 500 and let say if qty goes above 8,12,16 it should repeat

table for easy understanding sorry for being to detailing

QTY ADD. Total
1. 500. 500
2 125 625
3 125. 750
4. 125. 875
5. 500. 1375
6. 125. 1500
7. 125. 1625
8. 125. 1750
9. 500. 2250
and so on no limits
pls need help

Edit fiddle - JSFiddle - Code Playground[^]

What I have tried:

tried searching for it maybe i dont know the right terminology to search for it . please if you could shred some light and help me out pls.
Posted
Updated 9-Sep-22 3:36am

1 solution

Start with the value set to zero.
Start a loop from 1 to 5
If the loop counter equals 1 add 500 to the value
If the loop counter is less than 5 add 125 to the value
If the loop counter equals 5, reset it to 1 and restart the loop.

That should keep going to the end of time.
 
Share this answer
 
Comments
MZain Asif 9-Sep-22 9:59am    
can you give an example pls as loop word is something new for me i went through loop just now they got so many loop in loop info
Richard MacCutchan 9-Sep-22 10:21am    
If you do not understand loops then why are you trying to write this code. Go to JavaScript Tutorial[^] and study the examples.
MZain Asif 9-Sep-22 10:56am    
practical examples teach quicker i guess
i can learn loop but to apply i might need example like what goes where and how so thats why wanted an example in such scenario so i could try more complicated like what if after this let say qty reach 30 or abaove then we add % discount but thats like next step and will make things more complicated
Richard MacCutchan 9-Sep-22 11:03am    
Well if you had bothered to follow the link I gave you you would have found practical examples on every page of the tutorial.
MZain Asif 9-Sep-22 11:07am    
i did they have so many kind of loop and went through each but couldnt see anything related to this matter if you can bring some detail which loop is suitable for this and would be used for this scenario

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