JavaScript01

根据当前时间显示问候语

var today = new Date();
var hourNow = today.getHours();
var greeting;

if (hourNow > 18) {
    greeting = 'Good evening';
} else if (hourNow > 12) {
    greeting = 'Good afternoon';
} else if (hourNow > 0) {
    greeting = 'Good morning';
}  else {
    greeting = 'Welcome';
}
document.write(greeting);

 

posted @ 2018-08-17 16:14  小杜要加油  阅读(139)  评论(0编辑  收藏  举报