solved problem 1 again in javascript