-1
I need to do a function that returns how many times the car board appears in the array and use this return in another function to determine a calculation.
That’s my code and it’s printing "0"
var placas = [
'RXB-2525', 'AKX-3333', 'ORO-7142','RXB-2525', 'AKX-3333', 'ORO-7142',
'AKX-3333', 'RXB-2525', 'AKX-3333','AKX-3333', 'RXB-2525', 'AKX-3333',
'RXB-2525','AKX-3333','ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'ORO-7142', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'AKX-3333', 'RXB-2525','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'ORO-7142', 'ORO-7142','AKX-3333', 'ORO-7142', 'ORO-7142',
'ORO-7142', 'RXB-2525', 'AKX-3333','AKX-3333', 'ORO-7142', 'ORO-7142',
'AKX-3333', 'RXB-2525', 'AKX-3333','AKX-3333', 'RXB-2525', 'AKX-3333',
'RXB-2525', 'AKX-3333', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'ORO-7142', 'ORO-7142','AKX-3333', 'AKX-3333', 'RXB-2525',
'AKX-3333', 'AKX-3333', 'RXB-2525','AKX-3333', 'AKX-3333', 'RXB-2525'];
var numeroDeEntradas = 0;
var pagamentoUm = 0;
var pagamentoDois = 0;
function calcularNumeroDeEntradas(placa){
for (var i = 0; i < placas.length;i++){
if (placas[i]==placas[i]){
return numeroDeEntradas++;
}
}
}
function calcularValorDevido(placa){
if (calcularNumeroDeEntradas(placa)<=20){
pagamentoUm = 20*calcularNumeroDeEntradas(placa)
} else if (calcularNumeroDeEntradas(placa) >=20) {
pagamentoDois= pagamentoUm +(5*(calcularNumeroDeEntradas(placa)-20))
}
}
console.log(calcularNumeroDeEntradas(placas))
console.log(calcularValorDevido(placas))
"paymentUm" and "paymentDois" is the amount to be paid depending on the number of times the board repeats.
placas[i]==placas[i]
Shouldn’t that always be the same? It’s like asking 1==1... should just add, and return the variablenumeroDeEntradas
at the end of the function, after thefor
– Ricardo Pontual
can’t understand what exactly you want in the calculator functionValue on the if Else part. No sense in paying.
– user60252