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

141
Visualizações
Simple Js function giving me undefined as output

I am trying to solve this simple js function question but its giving the undefined as output along with the correct answer. I know its probably because of the return value issue but how solve in this situation?

function findMax(a,b,c){
    if(a>b && a>c){
        console.log("a" + " is max")
    }else if(a<b && b>c){
        console.log("b" + " is max")
    }else{
        console.log("c" + " is max")
    }
}
console.log(findMax(2,4,5))
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

your console logging the return value which is undefined. just get rid of the last con sole log.

function findMax(a,b,c){
    if(a>b && a>c){
        console.log("a" + " is max")
    }else if(a<b && b>c){
        console.log("b" + " is max")
    }else{
        console.log("c" + " is max")
    }
}
findMax(2,4,5);

Or you could return the string


function findMax(a,b,c){
    if(a>b && a>c){
        return "a" + " is max";
    }else if(a<b && b>c){
        return "b" + " is max";
    }else{
        return "c" + " is max";
    }
}
console.log(findMax(2,4,5))
about 4 years ago · Juan Pablo Isaza Relatório

0

You need to return value out to the outermost level. You can just return simple string, so you can log or do something else to the returned value.

function findMax(a, b, c) {
    if (a > b && a > c) {
        return "a" + " is max"
    } else if (a < b && b > c) {
        return "b" + " is max"
    } else {
        return "c" + " is max"
    }
}
console.log(findMax(2, 4, 5))
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