Problems 8 and 9 in js