-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabout.html
119 lines (102 loc) · 4.49 KB
/
about.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>about age machine</title>
<link rel="stylesheet" href="about.css">
</head>
<body>
<h4>a simple magic genie that knows your age</h4>
<p>we track age as a cookie</p>
<h1>the genies magic:</h1>
<p>dont tell him, his magic is supossed to be secret</p>
<h6 class="codeuse">free to use code</h6>
<div class="code">
<p class="codetxt">html:</p>
<code>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=, initial-scale=1.0">
<title>Age Machine</title>
<script src="scripts.js"></script>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<center>
<h1>AgE MACHINE</h1><br>
</center>
<button onclick="Enter()">Magic Genie</button>
<a href="about.html"><button>about</button></a>
</body>
</html>
</code>
<p class="codetxt">css:</p>
<code>
body {
background-color: orange;
}
button {
border-color: coral;
color: aqua;
background-color: chocolate;
font-family: monospace,verdana;
}
h1 {
font-family: Verdana, Geneva, Tahoma, sans-serif;
color: aqua;
}
p {
color: aqua;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
</code>
<p class="codetxt">js:</p>
<code>
/* original javascript: function Enter() {
age = window.prompt("what year were you born")
yearsold = 2023 - age;
window.alert("you are " + yearsold + " years old")
}*/
function Enter() {
// Get the current date
const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const currentMonth = currentDate.getMonth() + 1; // Note: months are 0-indexed, so add 1
const currentDay = currentDate.getDate();
// Prompt for the year of birth
let birthYear;
do {
birthYear = window.prompt("Enter the year of your birth (between 1800 and " + currentYear + "):");
} while (isNaN(birthYear) || birthYear < 1800 || birthYear > currentYear);
// Prompt for the month of birth
let birthMonth;
do {
birthMonth = window.prompt("Enter the month of your birth (between 1 and 12):");
} while (isNaN(birthMonth) || birthMonth < 1 || birthMonth > 12);
// Prompt for the day of birth
let birthDay;
do {
birthDay = window.prompt("Enter the day of your birth (between 1 and 31):");
} while (isNaN(birthDay) || birthDay < 1 || birthDay > 31);
// Calculate age based on the provided birthdate
const birthDate = new Date(birthYear, birthMonth - 1, birthDay); // Note: months are 0-indexed in JavaScript
// Calculate the age in years, months, and days
const ageInMilliseconds = currentDate - birthDate;
const millisecondsInYear = 365.25 * 24 * 60 * 60 * 1000;
const years = Math.floor(ageInMilliseconds / millisecondsInYear);
const remainingMilliseconds = ageInMilliseconds % millisecondsInYear;
const millisecondsInMonth = millisecondsInYear / 12;
const months = Math.floor(remainingMilliseconds / millisecondsInMonth);
const remainingDays = Math.floor((remainingMilliseconds % millisecondsInMonth) / (24 * 60 * 60 * 1000));
// Display the result
window.alert("You are " + years + " years, " + months + " months, and " + remainingDays + " days old.");
console.log("You are " + years + " years, " + months + " months, and " + remainingDays + " days old.");
}
</code>
</div>
</body>
</html>