JS Solution to Problem 13