Last active
May 6, 2019 08:51
-
-
Save Rukeeo1/9a39f46d8905e64aabe3ebba309aae16 to your computer and use it in GitHub Desktop.
The addNumber function returns the sum of two Integers
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 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