JSFiddle - React, Tailwind, and code Playground
by Edi Carlos
JavaScript
const listaDePetShops = [
{ nome: 'petShopA', precoP: 30, precoG: 50, tosa: 25, dist: 3 },
{ nome: 'petShopB', precoP: 20, precoG: 55, tosa: 35, dist: 2 },
{ nome: 'petShopC', precoP: 35, precoG: 45, tosa: 25, dist: 4 },
{ nome: 'petShopD', precoP: 32, precoG: 46, tosa: 30, dist: 2.5 },
{ nome: 'petShopE', precoP: 40, precoG: 45, tosa: 22, dist: 7 },
]
const percentage = 20.0;
calculaCusto(5, 7, true, true)
function calculaCusto(qtdPequeno, qtdGrande, eFinalSemana, tosa) {
for (let i = 0; i < listaDePetShops.length; i++) {
let somaTosa = (listaDePetShops[i].tosa * qtdPequeno) + (listaDePetShops[i].tosa * qtdGrande);
let somaBanho = (qtdPequeno * listaDePetShops[i].precoP) + (qtdGrande * listaDePetShops[i].precoG);
let somaBanhoTosa = somaTosa + somaBanho;
let somaBanhoComAcres = somaBanho + somaBanho / 100 * percentage;
let somaBanhoTosaComAcres = somaBanhoTosa + somaBanhoTosa / 100 * percentage;
//console.log(listaDePetShops[i].nome + ' banho é: ' + somaBanho);
//console.log(listaDePetShops[i].nome + ' banho + tosa é: ' + somaBanhoTosa);
// console.log(listaDePetShops[i].nome + ' no final de semana banho é: ' + somaBanhoComAcres);
console.log(listaDePetShops[i].nome + ' no final de semana banho + tosa é: ' + somaBanhoTosaComAcres);
}
}