JavaScript solving problems