Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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))

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading