Skip to content

Instantly share code, notes, and snippets.

@DevGW
Last active April 5, 2023 14:44
Show Gist options
  • Save DevGW/0125de042c4c9e6007cfd0c3faa782fb to your computer and use it in GitHub Desktop.
Save DevGW/0125de042c4c9e6007cfd0c3faa782fb to your computer and use it in GitHub Desktop.
Javascript :: else if #js
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