Problem 8. in Javascript