Category: FCC Algorithm Challenges

FCC Bonfire Series 142: Validate US Telephone Numbers

This post marks the beginning of the end. The end of the Free Code Camp bonfires. Ths time, we are going to be tackling the first bonfire in the advanced (or upper advanced) section. It deals […]

FCC Bonfire Series 138: Arguments Optional

Arguments Optional, oh boy, this is the last challenge before we get to the advanced bonfires section. This bonfire will show us some very interesting facts about JavaScript functions.

For this task, we are asked to write a function that accepts either one or two arguments. If two arguments are provided (and both are numbers), we proceed to return the sum; but, if we are only given a single argument, we must return a function. This returned function will accept one number as argument, and will return the sum of it and the originally passed number. Let’s see a few examples:

addTogether(5, 6);      //-> 11
add(11, 53);    //-> 64

var addFive = addTogether(5);
addFive(6);     //-> 11

var addEleven = addTogether(11);
addEleven(53);  //-> 64