javascript problem solving