How to simplify JavaScript code?

The user enters the number of sold coffee all day
by the formula ( кофе1_мл * кофе1_колличество)+(кофе2_мл*кофе2_колличество).....(кофе3_мл..)= "spent total"+ itogoml +" ml";

if there is 100 items,how do I simplify the code to loop or make it easier?

<input type="hidden" id="cofe1" value="1.50">
<input type="hidden" id="cofe2" value="3.40">
<button onclick="jQuery('#N1').val(parseInt(jQuery('#N1').val())-1);jQuery('#N1').change();">-</button>
<input type="number" id="N1" value="0" placeholder="Number of PCs sold">
<button onclick="jQuery('#N1').val(parseInt(jQuery('#N1').val())+1);jQuery('#N1').change();">+</button>
<br / >

<button onclick="jQuery('#N2').val(parseInt(jQuery('#N2').val())-1);jQuery('#N2').change();">-</button>

<input type="number" id="N2" value="0" placeholder="Number of PCs sold">
<button onclick="jQuery('#N2').val(parseInt(jQuery('#N2').val())+1);jQuery('#N2').change();">+</button>
<button onclick="raschitat();">Calculate cost</button>
<div id="vsegostuk"></div>
<div id="vsegoml"></div>
<div id="summaprod"></div>

<script type="text/javascript">
raschitat function() {
var a = parseInt(document.getElementById('N1').value);
var b = parseInt(document.getElementById('N2').value);
var c = a + b ;
document.getElementById('vsegostuk').innerHTML = a + " + "+ b + " = " + c;


var cofe1 = parseFloat(document.getElementById('cofe1').value);
var cofe2 = parseFloat(document.getElementById('cofe2').value);
var itogoml = (cofe1 * a) + (cofe2 * b) ;
document.getElementById('vsegoml').innerHTML = "You have just spent"+ itogoml +" ml";

summaprod = c * 10;
document.getElementById('summaprod').innerHTML = "You have sold goods to the amount of "+ summaprod +" R";
}
</script>
June 3rd 19 at 19:00
3 answers
June 3rd 19 at 19:02
Solution
jsfiddle.net/8uow6n3y

It is not clear why you have an additional +/- buttons next to input type=number, it is embedded there:
dQ94Po.png

If you are not going to throw them away, you probably will have to add on minus checks for a negative number.
but if the goods will be 100?
the formula will be (volume1 * a) + (volume2 * b)+(volume3*c)+.......(volume100*aaa)
const totalVolume = (volume1 * a) + (volume2 * b)
 const sum = (a + b) * 10;

and my question is how to reduce a formula)
on account of the + and - buttons I want to draw to the phone is more convenient you can press - Jalen_Rat commented on June 3rd 19 at 19:05
it?
jsfiddle.net/8uow6n3y/2 - Austen.Thompson53 commented on June 3rd 19 at 19:08
Yes)) thank you very much,that's what I needed ^_^
I have tried using a two-dimensional array to do it - Jalen_Rat commented on June 3rd 19 at 19:11
well , as it will be for 100 products?? the sheet will be... able to do, hands down.. he is right now I would say that generally not 100 but 500 products... the same combination with the syrups.. and even cakes want here))) - ted_Leuschke commented on June 3rd 19 at 19:14
don't forget to mark solution - Myrtis commented on June 3rd 19 at 19:17
and if let's say I want to add a new variable grams?

just input field can only be one name"x" - Jalen_Rat commented on June 3rd 19 at 19:20
so go?
jsfiddle.net/8uow6n3y/5 - Austen.Thompson53 commented on June 3rd 19 at 19:23
June 3rd 19 at 19:04
Or am I wrong or the author of the half has not announced, but should be like this:
1. dropdown select with the types of coffee there these your 100 positions
2. input for the number (or again select, if number is integer, XS, of the question is unclear)
3. the ENTER button the selected option
4. button TOTAL
5. ALL! )))

thus, the operator selects in the select the coffee type, enters the number, presses enter, then repeats as necessary times, and at the end clicks TOTAL

script there for 12 strings, can distribute when the time would be so full of cases, at least here right now brandy is heated
June 3rd 19 at 19:06
And what parseInt and parseFloat if further addition and multiplication is? Js himself can types to convert

Find more questions by tags JavaScript