Skip to content

Instantly share code, notes, and snippets.

@jw-jenrise
Last active January 25, 2018 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jw-jenrise/f48fbaa938cac96eba70465624a2b1cc to your computer and use it in GitHub Desktop.
Save jw-jenrise/f48fbaa938cac96eba70465624a2b1cc to your computer and use it in GitHub Desktop.
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