Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda