solved problem 2 again in javascript