Incomplete Function

Asked

Viewed 583 times

-2

I need to know where the error is in the following function:

function quantidadeDeMesesComLucro(umPeriodo) {
  let quantidade= ????;
  for (let mes=0; mes< umPeriodo.length; mes++) {
    ????
  }
  return quantidade;
}

I tried to complete, but I can’t, follow my code:

function quantidadeDeMesesComLucro(umPeriodo) {
  let quantidade= 0;
  for (let mes=0; mes< umPeriodo.length; mes++) {
    quantidade = umPeriodo[mes]
   
    
  }
  return quantidade;
}

This is a question of an exercise and I can’t figure out the mistake, someone can help me?

  • Your question seems to have some problems and your experience here in Stack Overflow may not be the best because of this. We want you to do well here and get what you want, but for that we need you to do your part. Here are some guidelines that will help you: Stack Overflow Survival Guide in English.

  • it’s hard to know the error when we don’t know the purpose.

  • What kind of error do you refer to? Error that appears on the console or is simply not running correctly? " quantity = one month[month]" should be "quantity += one month]"

  • the exercise only asks to complete the function, so I could not :(

1 answer

0


In order to complete the function would need to know what is considered a month with profit, as I did not understand I will leave in this form:

function quantidadeDeMesesComLucro(umPeriodo) {
    let quantidade = 0;
    for (let mes=0; mes< umPeriodo.length; mes++) {
        if(*houver lucro em umPeriodo[mês]*) {
            quantidade = quantidade + 1 (ou quantidade += 1)
        }
    }
    return quantidade;
}
  • Thanks André, that’s right, now I understand the mistake, thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.