🔸 You are 1 year old at birth (not 0)
🔸 Age increases every January 1st (not on your birthday)
🔸 Your Kazoedoshi age is ${kazoedoshi} — ${kazoedoshi - westernAge} year${kazoedoshi - westernAge !== 1 ? 's' : ''} more than Western age
📝 Note: Japan officially switched to Western age system in 1902, but Kazoedoshi is still used in traditional ceremonies, New Year celebrations, and some Buddhist rituals.
`;// Fun Facts buildFunFacts(westernAge, kazoedoshi, zodiac, birthEra, season, y);// Show results document.getElementById('jacResults').style.display = 'block'; document.getElementById('jacResults').scrollIntoView({ behavior: 'smooth', block: 'start' }); };// ── Build Timeline ──────────────────────────────────────── function buildTimeline(birth, today) { const container = document.getElementById('resEraTimeline'); container.innerHTML = '';ERAS.forEach(era => { const eraEnd = era.end || today; if (birth > eraEnd) return;const isActive = (era.end === null) || (today >= era.start && today <= era.end); const bornInEra = birth >= era.start; const startYear = bornInEra ? birth.getFullYear() : era.start.getFullYear(); const endYear = (era.end && era.end < today) ? era.end.getFullYear() : today.getFullYear(); const yearsLived = endYear - startYear + (bornInEra ? 0 : 1);const item = document.createElement('div'); item.className = 'jac-timeline-item' + (isActive ? ' active' : ''); item.innerHTML = `
${era.kanji} ${era.name} Era (${era.roman})
${bornInEra ? `You were born in this era` : `Era started before your birth`}
— lived approximately ${yearsLived} year${yearsLived !== 1 ? 's' : ''} in this era
${isActive ? ' (Current Era ✓)' : ''}
`;
container.appendChild(item);
});
}// ── Build Fun Facts ───────────────────────────────────────
function buildFunFacts(western, kazoe, zodiac, birthEra, season, birthYear) {
const ul = document.getElementById('resFunFacts');
ul.innerHTML = '';const facts = [
`🎌 In Japan, you would be called ${kazoe} years old in traditional ceremonies`,
`🐉 Your Japanese Zodiac is the ${zodiac.emoji} ${zodiac.name} — ${zodiac.desc}`,
`🌸 You were born in ${season.name} — Japanese season: ${season.jp}`,
`🏯 You were born in the ${birthEra ? birthEra.name : 'Showa'} Era of Japan`,
`🎋 In Japan, age ${western} is written as ${western}歳 (${western} sai)`,
`🎍 The Japanese New Year (正月 Shōgatsu) is the most important time — your Kazoedoshi increases then!`,
];if (western >= 20) facts.push(`🍶 In Japan, 20 years old (成人式 Seijin-shiki) is the Coming of Age ceremony — a major milestone!`);
if (western >= 60) facts.push(`🎊 At 60 years old (還暦 Kanreki), Japanese celebrate completing one full zodiac cycle — a grand birthday!`);
if (western >= 70) facts.push(`🌟 At 70 years old (古希 Koki), Japanese celebrate with special traditions from ancient Chinese poetry!`);
if (western >= 77) facts.push(`🎉 At 77 years old (喜寿 Kiju), the character 喜 (joy) resembles 七十七 — a special Japanese celebration!`);
if (western >= 88) facts.push(`✨ At 88 years old (米寿 Beiju), the character 米 (rice) resembles 八十八 — rice is sacred in Japan!`);
if (western >= 99) facts.push(`👑 At 99 years old (白寿 Hakuju), removing one stroke from 百 (100) gives 白 (white) — incredibly rare milestone!`);facts.forEach(f => {
const li = document.createElement('li');
li.innerHTML = f;
ul.appendChild(li);
});
}// ── Copy ──────────────────────────────────────────────────
window.copyJACResult = function() {
const westernAge = document.getElementById('resWesternAge').textContent;
const kazoe = document.getElementById('resKazoedoshi').textContent;
const era = document.getElementById('resEraName').textContent;
const eraYear = document.getElementById('resEraYear').textContent;
const zodiac = document.getElementById('resZodiac').textContent;const text = `Japanese Age Calculator Results:
Western Age: ${westernAge} years old
Kazoedoshi (Traditional Japanese): ${kazoe} years old
Current Japanese Era: ${era} ${eraYear}
Japanese Zodiac: ${zodiac}`;navigator.clipboard.writeText(text)
.then(() => showToast('✅ Copied!'))
.catch(() => showToast('❌ Copy failed'));
};// ── Share ─────────────────────────────────────────────────
window.shareJACResult = function() {
const westernAge = document.getElementById('resWesternAge').textContent;
const kazoe = document.getElementById('resKazoedoshi').textContent;
const era = document.getElementById('resEraName').textContent;
const zodiac = document.getElementById('resZodiac').textContent;const text = `I calculated my Japanese age! 🎌 Western: ${westernAge} years | Kazoedoshi: ${kazoe} | Era: ${era} | Zodiac: ${zodiac}`;if (navigator.share) {
navigator.share({ title: 'Japanese Age Calculator', text }).catch(() => {});
} else {
showToast('📋 Use Copy instead!');
}
};// ── Reset ─────────────────────────────────────────────────
window.resetJAC = function() {
daySelect.value = '';
document.getElementById('jacMonth').value = '';
yearSelect.value = '';
document.getElementById('jacError').style.display = 'none';
document.getElementById('jacResults').style.display = 'none';
};// ── Toast ─────────────────────────────────────────────────
function showToast(msg) {
const t = document.createElement('div');
t.textContent = msg;
t.style.cssText = 'position:fixed;bottom:24px;left:50%;transform:translateX(-50%);background:#C62828;color:#fff;padding:12px 20px;border-radius:10px;font-size:14px;font-weight:600;z-index:9999;box-shadow:0 4px 15px rgba(0,0,0,0.3);';
document.body.appendChild(t);
setTimeout(() => t.remove(), 2200);
}})();