Solved Problem 21 in JS