-4
Good Afternoon!
Given the function
function caixaEletronico(amount){
let totalAvailable = 1000
let cedulas = [200,100,50,20,10,5,2]
if (isNaN(amount) || typeof(amount) === 'string' || amount < 1 || amount > totalAvailable || amount === 3 || amount === 1) {
return console.log(
" Valor incorreto!! Cédulas disponíveis neste terminal: R$2,00 R$5,00 R$10,00 R$20,00 R$50,00 R$100,00 R$200,00 | Limite saque R$1.000,00"
);
}
const newArrCedulas = cedulas.map(function(cedula) {
cedulas = Math.floor(amount / cedula)
amount -= cedulas * cedula
return cedulas
})
console.log(
`Notas entregues:
${newArrCedulas[0]} nota(s) de R$200,00, ${newArrCedulas[1]} nota(s) de R$100,00, ${newArrCedulas[2]} nota(s) de R$50,00 e ${newArrCedulas[3]} nota(s) de R$20,00, ${newArrCedulas[4]} nota(s) de R$10,00, ${newArrCedulas[5]} nota(s) de R$5,00, ${newArrCedulas[6]} nota(s) de R$2,00`
)
}
caixaEletronico(88)
I’m having trouble specifically returning in some even numbers this is one of them, where the number 8 should return 4 2 ballots.
In case anyone can help me with the validation.
Thank you very much! I lost myself with the return of the function, but now I understand. Vlw!
– Kaio rocha ribeiro