Added JavaScript solution for problem 6