JS Problem 2 Solution with comments