Problem 6 in js