write a js code to display the greater of two numbers using if.... else
Answers
Answered by
0
Answer:
function largest(a, b) {
if(a > b)
return a;
else if(a === b)
return 0;
else
return b;
}
Explanation:
As told above, inside the function with two parameters a and b we are comparing in the if condition if a is greater than b. If this condition holds true, then return the first element, a here. Then we check for else if, both the elements are equal, then return 0, since none of them is largest and our function will cleverly return false or 0. Otherwise, return b, since if a is not greater and equal to b, therefore it must be smaller than b. Therefore, we return b.
Similar questions