Skip to content

Instantly share code, notes, and snippets.

@Rukeeo1
Last active May 6, 2019 08:51
Show Gist options
  • Save Rukeeo1/9a39f46d8905e64aabe3ebba309aae16 to your computer and use it in GitHub Desktop.
Save Rukeeo1/9a39f46d8905e64aabe3ebba309aae16 to your computer and use it in GitHub Desktop.
The addNumber function returns the sum of two Integers
function addNumber(a, b) {
//check to see that 'a' and 'b' are numbers
if (typeof a !== "number" || typeof b !== "number") {
return "first and second parameter's must be numbers";
}
/* sum both numbers */
let sum = a + b;
/* if it's an Integer return 'sum', else for floating point numbers approximate to two decimal place*/
if (Number.isInteger(sum)) {
return sum;
} else {
/* this handles floating point numbers...app*/
return Number(sum.toFixed(2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment