Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
how make output "Negative!" at console.log(question4([-1, 4, 7, 11]))
function question4(angka){
var w=0 , jml=0, rtt=0;
var nilai;
nilai=angka;


for(w=0;w < nilai.length;w++)
{
jml=jml+nilai[w];
}
rtt=jml/nilai.length;
console.log(rtt);
}

console.log(question4([4, 5, 6, 7, 8]));
console.log(question4([100, 200, 300, 400, 500]));
console.log(question4([-1, 4, 7, 11]));

If there is one or more array elements with negative values, then the function is direct outputs the text 'Negative!'.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

First of all you don't have to call the question4() within a console.log() because the question4() doesn't return anything, instead check in the loop if (nilai[w] < 0) console.log('Negative!')

about 4 years ago · Juan Pablo Isaza Relatório

0

Maybe you can use this

function hasArrayNegativeValue(valueArray){

for(i=0;i < valueArray.length;i++)
   {
     if(valueArray[i] < 0){
       return 'Negative';
      
       }
       
   }
  return null;
}

console.log(hasArrayNegativeValue([4, 5, 6, 7, 8]));
console.log(hasArrayNegativeValue([100, 200, 300, 400, 500]));
console.log(hasArrayNegativeValue([-1, 4, 7, 11]));
about 4 years ago · Juan Pablo Isaza Relatório

0

it is so easy, question4 function must return a value..

    function question4(angka){
        for(w=0;w < angka.length;w++)
        {
          if(angka[w]<0)
            {
              return "Negative";
            }
        }

  return "Posetive";

}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda