حسابي

بحث

القائمة

تفاصيل العمل

بكل بساطة تكتب تاريخ ميلادك سيعطيك عمرك الدقيق مثلا (عمرك.....سنة/.....شهور/.....ايام/......ساعات/.......دقائق/........ثونِ)

اليك الكود كامل انسخه

<!DOCTYPE html>

<html lang="ar">

<head>

<meta charset="UTF-8" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<title>حساب العمر</title>

<style>

body {

font-family: Arial, sans-serif;

direction: rtl;

text-align: center;

margin: 20px;

background-color: #12b6d33e;

}

.container {

max-width: 400px;

margin: auto;

background: rgba(250, 67, 222, 0.234);

padding: 20px;

box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);

border-radius: 10px;

}

h1 {

color: #333;

}

input,

button {

margin: 11px 0;

padding: 10px;

width: 100%;

font-size: 16px;

}

button {

background: #de6d26;

color: white;

border: none;

cursor: pointer;

}

button:hover {

background: #86cb3c;

}

</style>

<script>

function calculateAge() {

let birthDate = document.getElementById("birthDate").value;

if (!birthDate) {

alert("يرجى إدخال تاريخ الميلاد");

return;

}

let birth = new Date(birthDate);

let now = new Date();

let years = now.getFullYear() - birth.getFullYear();

let months = now.getMonth() - birth.getMonth();

let days = now.getDate() - birth.getDate();

let hours = now.getHours() - birth.getHours();

let minutes = now.getMinutes() - birth.getMinutes();

let seconds = now.getSeconds() - birth.getSeconds();

if (seconds < 0) {

seconds += 60;

minutes--;

}

if (minutes < 0) {

minutes += 60;

hours--;

}

if (hours < 0) {

hours += 24;

days--;

}

if (days < 0) {

let previousMonth = new Date(now.getFullYear(), now.getMonth(), 0);

days += previousMonth.getDate();

months--;

}

if (months < 0) {

months += 12;

years--;

}

document.getElementById(

"result"

).innerText = `عمرك هو: ${years} سنة و ${months} شهر و ${days} يوم و ${hours} ساعة و ${minutes} دقيقة و ${seconds} ثانية`;

}

</script>

</head>

<body>

<div class="container">

<h1>حاسبة العمر</h1>

<p>أدخل تاريخ ميلادك لحساب عمرك</p>

<input type="date" id="birthDate" />

<button onclick="calculateAge()">احسب العمر</button>

<p id="result"></p>

</div>

</body>

</html>

ملفات مرفقة

بطاقة العمل

اسم المستقل احمد ا.
عدد الإعجابات 0
عدد المشاهدات 3
تاريخ الإضافة
تاريخ الإنجاز