solved problem #7 on javaScript