JS Solution for Problem 14