-2
I’m trying to do an exercise, but it was not the way the platform wanted, I’m without ideas on how to solve, I’m on my first day of javascript.... Follow the statement, the error and my attempt.
A company sent a list containing the monthly numbers of everything she billed, and our job is to help them create a report that shows how many months they had the negative balance.
var listaDeGanhos = [10, 30, -10, -5, -1, 40]
Based on the array above, which is available in the code, loop check how many months have had negative values and store the count a variable called totalNegative which is also available in the code.
In the Code it’s already written
var listaDeGanhos = [10, 30, -10, -5, -1, 40]
var totalNegativos = 0
//minha tentativa
for ( var i = 0; i < listaDeGanhos.length; i++){
numeros = listaDeGanhos[i]
if ( numeros < 0 ){
console.log(totalNegativos++)
}
}
Error I get : You should check if the current value of the array is negative with an if
Would it be possible to be more clear about the problem? Your code is working correctly. If the problem is in relation to printing, just put the operator
++
before the variable. This way the increment will happen before printing the value.– JeanExtreme002
Hard to say what’s wrong, because it looks like the problem is in the algorithm that’s analyzing the logic of your code. I would deduce that he is failing to interpret this indirect that you created with the variable
numeros
, he must be hoping that inif
you useif (listaDeGanhos[i] < 0)
, but that’s just a hunch, because there’s no way to replicate your problem.– Andre
@user140828 was exactly that, the algorithm of the platform I am using did not recognize the variable numbers. I did as you indicated and it worked, thank you.
– xBrn0xy