Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

make changes in css file in age claculator folder#10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletionprojects/age-calculator/index.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,17 +7,22 @@
<title>Age Calculator</title>
<link rel="stylesheet" href="style.css">
</head>

<body>
<div class="container">
<h1>Age Calculator</h1>
<div class="form">
<label for="birthday">Enter you date of birth</label>

<input type="date" id="birthday" name="birthday">

<button id="btn">Calculate Age</button>
<p id="result">Your age is 21 years old</p>
<h2 id="wel" > Welcome Guys !</h2>
</div>
</div>

<script src="index.js"></script>
</body>
</html>
</html>

29 changes: 18 additions & 11 deletionsprojects/age-calculator/index.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,30 +2,37 @@ const btnEl = document.getElementById("btn");
const birthdayEl = document.getElementById("birthday");
const resultEl = document.getElementById("result");

function Welcome(){
// welcome.innerHTML = "<p> Thanks !</p>" ;
console.log("thanks") ;
}
function calculateAge() {

const birthdayValue = birthdayEl.value;

if (birthdayValue === "") {
alert("Please enter your birthday");
} else {
const age = getAge(birthdayValue);
resultEl.innerText = `Your age is ${age} ${age > 1 ? "years" : "year"} old`;
}

}

function getAge(birthdayValue) {
const currentDate = new Date();
const birthdayDate = new Date(birthdayValue);
let age = currentDate.getFullYear() - birthdayDate.getFullYear();
const month = currentDate.getMonth() - birthdayDate.getMonth();

if (
month < 0 ||
(month === 0 && currentDate.getDate() < birthdayDate.getDate())
) {
age--;
}
let age = currentDate.getFullYear() - birthdayDate.getFullYear(); // current year - birtday date year --> 2023 - 1972
const month = currentDate.getMonth() - birthdayDate.getMonth(); //current mont - birtdaymonth 4 - 12 = -8

return age;
if (month < 0 || (month === 0 && currentDate.getDate() < birthdayDate.getDate())) {
return --age;
}


}

btnEl.addEventListener("click", calculateAge);
btnEl.addEventListener("click",
calculateAge ,

);
22 changes: 17 additions & 5 deletionsprojects/age-calculator/style.css
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
*{
padding: 0;
margin: 0;
}
body {
margin: 0;
padding: 20px;
font-family: "Montserrat", sans-serif;
background-color: #f7f7f7;
/* background-color: #f7; */
background-image: radial-gradient( circle , red , blue , green ,yellow , white );
}

.container {
background-color: white;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
background-color: rgb(205, 60, 60);
/* box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); */
box-shadow: 3px 5px red, -1em 0 .4em rgb(221, 221, 73);
padding: 20px;
max-width: 600px;
margin: 0 auto;
border-radius: 5px;
margin-top: 50px;
height: 50vh;
color: white;
}

h1 {
Expand All@@ -21,7 +29,10 @@ h1 {
margin-top: 0;
margin-bottom: 20px;
}
#wel{

padding-top: 20px;
}
.form {
display: flex;
flex-direction: column;
Expand All@@ -40,7 +51,6 @@ input {
width: 100%;
max-width: 300px;
}

button {
background-color: #007bff;
color: white;
Expand All@@ -53,9 +63,11 @@ button {
}

button:hover {
background-color: #0062cc;
background-color: #c9cc00;

}


#result {
margin-top: 20px;
font-size: 24px;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp