0
It has this function to find out how many months a person’s balance was positive:
function quantidadeDeMesesComLucro(umPeriodo){
let quantidade = 0;
for(let mes = 0; mes < umPeriodo.length; mes++){
if(umPeriodo[mes] > 0)
quantidade += 1;
}
return quantidade;
}
Now I needed to write a code (in the same structure as this above) to know how many months of a period there was loss (when the balance is less than zero).
Then that would be the first question, to write the function quantity.
To second question would that be:
Knowing the balance of the months with profit
Complete the function saldoDeMesesComLucro. Again it has a structure similar to the previous problems, but not so fast! This function needs to return an array.
balances [100, 20, 10]
Somebody please help me
Ah got it! In the case the reasoning of the function quantityDeMesesComPerda is to return a number, that’s why the counter is used. And in the reasoning of the second function, I’m returning a value within the array right, so the push method. That would be about it?
– Thiago Lima
Yeah, that’s right, that’s right.
– Daniel Mendes