Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (51 loc) · 1.63 KB
/
Copy pathscript.js
File metadata and controls
62 lines (51 loc) · 1.63 KB
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
document.getElementById("akanForm").addEventListener("submit", function (e) {
e.preventDefault();
// Retrieve user input
const birthdate = document.getElementById("birthdate").value;
const gender = document.getElementById("gender").value;
const result = document.getElementById("result");
if (!birthdate || !gender) {
result.innerText = "⚠️ Please enter your birthdate and select gender.";
return;
}
// Split date into components
const dateObj = new Date(birthdate);
const DD = dateObj.getDate();
const MM = dateObj.getMonth() + 1; // Months are 0-based in JS
const YYYY = dateObj.getFullYear();
// Validate input
if (DD < 1 || DD > 31) {
result.innerText = "⚠️ Day must be between 1 and 31.";
return;
}
if (MM < 1 || MM > 12) {
result.innerText = "⚠️ Month must be between 1 and 12.";
return;
}
// Extract CC and YY
const CC = Math.floor(YYYY / 100); // first two digits
const YY = YYYY % 100; // last two digits
// Apply formula
let d =
(CC / 4 - 2 * CC - 1 + (5 * YY) / 4 + (26 * (MM + 1)) / 10 + DD) % 7;
// Handle negative modulo in JS
d = ((Math.floor(d) % 7) + 7) % 7;
// Akan names mapping
const akanNames = {
male: ["Kwasi", "Kwadwo", "Kwabena", "Kwaku", "Yaw", "Kofi", "Kwame"],
female: ["Akosua", "Adwoa", "Abenaa", "Akua", "Yaa", "Afua", "Ama"],
};
const days = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
// Get name
const akanName = akanNames[gender][d];
// Display result
result.innerText = `You were born on a ${days[d]}. Your Akan name is: ${akanName}.`;
});