Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!