problem 2 solved with javascript