-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex22.html
38 lines (32 loc) · 982 Bytes
/
ex22.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Greeting Message</title>
</head>
<body>
<script>
document.addEventListener("DOMContentLoaded", function() {
var userName = prompt("Please enter your name:");
var now = new Date();
var hour = now.getHours();
var greeting = "";
if (hour < 12) {
greeting = "Good morning";
} else if (hour < 18) {
greeting = "Good afternoon";
} else {
greeting = "Good evening";
}
var greetingMessage = document.createElement("div");
greetingMessage.textContent = greeting + ", " + userName + "!";
greetingMessage.style.cursor = "pointer";
greetingMessage.addEventListener("click", function() {
greetingMessage.style.display = "none";
});
document.body.appendChild(greetingMessage);
});
</script>
</body>
</html>