4
I need to do an IF in Javascript. I will explain:
A customer sells:
- Barrels of 40kg.
- Tube of 3 kg.
I don’t know how to do this IF. The idea is, show in the field qtd40kg
Only multiples of 40, which is the weight, ie:
If I need 40k in the field shows 1, 80kg shows 2, 120kg shows 3, that’s because they are multiples of 40.
Now in the field qtd3kg
is a little different, it is multiples of 3kg that will fill the gap between qtd40kg
.
Link https://jsfiddle.net/2w84ec18/
Ex:
qtd40kg
40kg -> qtd40kg = 1un;
80kg -> qtd40kg = 2un;
120kg -> qtd40kg = 3un;
160kg -> qtd40kg = 4un;
.
.
.
Até 1.000kg
qtd3kg
0kg -> qtd3kg = 0un;
3kg -> qtd3kg = 1un;
3kg -> qtd3kg = 1un;
9kg -> qtd3kg = 2un;
.
.
.
Até 30kg, depois ele irá fazer assim:
Let’s assume that:
peso = 43;
Então ``qtd40kg = 1`` e ``qtd3kg = 1``.
peso = 46;
Então ``qtd40kg = 1`` e ``qtd3kg = 2``.
peso = 49;
Então ``qtd40kg = 1`` e ``qtd3kg = 3``.
peso = 126;
Então ``qtd40kg = 3`` e ``qtd3kg = 2``.
Link https://jsfiddle.net/2w84ec18/
Can anyone help me? This is a very high level for me.
I appreciate any help.
Hello @Bacco, edirei. I think better in JS. Thanks.
– Tiago
It got better. And if the person puts 5kg, or some other value that doesn’t give multiples, like 25kg, what is to happen?
– Bacco
@Bacco If it is 5kg it would be 2 tubes of 3kg. 25kg would be 9 tubes of 3kg. and in the field
qtd40kg
is ZERO, because the quantity is not equal to more than 40kg. Only from 40kg theqtd40kg
begins to receive value.– Tiago
You want for example: 0 to 39 = 0, 40 to 79 = 1, ... ? It’s like this?
– Samir Braga
@Bacco the function of
qtd3kg
is to fill the space that the 40kg barrels leave. From 40kg up to 80kg, has several kg to be filled. The 3kg tube is to fill this space, maximizing the amount of mass.– Tiago
And if the person wants 42, is a 40 and a 3, with a 1 kg error, or is 14 of 3, giving certinho 42?
– Bacco
@Bacco let’s assume you need 60kg of dough, more than that would throw away. If you only had a 40-pound barrel, then you’d have to buy 80 kilos, and 20 kilos would get lost. With the help of the 3kg tubes, it is possible to get as close as possible to the customer’s need. In this example of 60kg would be (1 of 40kg and 7 of 3kg), totaling 61kg. In this case the loss is only 1kg.
– Tiago
@Bacco, the tubes are more expensive, so can not direct. In your case above would be like this: Purchased 42kg would be 1un of 40kg and 1un of 3kg.
– Tiago