Its a relatively simple question however I wanted to see how other people would tackle the below issue:
- A user can enter (x) quantity in to text box txtUserInput
so for example UserInput = 14
- 1 box can contain upto 4 items.
so based on the above txtUserInput, I want the program to calculate how many boxes are required, (in this case the answer would be 4 boxes, with 2 spaces remaining in the final box.
below is an example of the code in its basic form:
var itemsCount = txtUserInput;
var boxes = 0;
if (itemsCount <=4) {
boxes ++;
}
else if (itemsCount <=8 && >4) {
boxes += 2;
}
as you can see, I could repeat this over and over again to get the correct result but it would become very tedious and a lot longer than it requires...
So using JavaScript how can I put this into an array/loop and get boxes to give me my desired output?
thankyou for your help