solving with javascript