Last active
April 5, 2023 14:44
-
-
Save DevGW/0125de042c4c9e6007cfd0c3faa782fb to your computer and use it in GitHub Desktop.
Javascript :: else if #js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function maxOfThree(num1, num2, num3) { | |
if (num1 > num2 && num1 > num3) { | |
return num1; | |
} else if (num2 > num1 && num2 > num3) { | |
return num2; | |
} else { | |
return num3; | |
} | |
} | |
function everyWhichWay(x, y, z) { | |
if (x + y === z) { | |
return 'sum'; | |
} else if (x - y === z) { | |
return 'difference'; | |
} else if (x * y === z) { | |
return 'product'; | |
} else if (x / y === z) { | |
return 'fraction'; | |
} else { | |
return null; | |
} | |
} | |
// another way to write top function (maxOfThree) using nested if statement | |
function getMax(firstNum, secondNum, thirdNum) { | |
if (firstNum > secondNum) | |
{if (firstNum > secondNum) { | |
return firstNum; | |
} return thirdNum; | |
} else if (secondNum > thirdNum) { | |
return secondNum; | |
} else { | |
return thirdNum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment