Last active
January 25, 2018 01:50
-
-
Save jw-jenrise/f48fbaa938cac96eba70465624a2b1cc to your computer and use it in GitHub Desktop.
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
console.log("Begin example - 6"); | |
// Adding of three numbers using a function | |
// Define an add function that can work for three or less arguments | |
function add(a,b,c){ | |
var d = ( (a) ? a : 0 ) + // Using ternary operator we can check the | |
( (b) ? b : 0 ) + // Truthy/Falsy of the parameter and then | |
( (c) ? c : 0 ) ; // Substitue with numeral zero so that NaN is avoided. | |
return d; | |
} | |
var result1 = add(1); | |
console.log("Result 1 =" + result1); | |
var result2 = add(10,20); | |
console.log("Result 2 =" + result2); | |
var result3 = add(100,200,300); | |
console.log("Result 3 =" + result3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment