Adding javascript solution for problem 3