Problem 18 in js