Add Problem 3 solution in Javascript