let getTimeState = () => {// 获取当前时间let timeNow = new Date();// 获取当前小时let hours = timeNow.getHours();// 设置默认文字let text = ``;// 判断当前时间段if (hours >= 0 && hours <= 10) {text = `早上好`;} else if (hours > 10 && hours <= 14) {text = `中午好`;} else if (hours > 14 && hours <= 18) {text = `下午好`;} else if (hours > 18 && hours <= 24) {text = `晚上好`;}// 返回当前时间段对应的状态return text;};alert(getTimeState())