gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
html css js code to track number of days passed since i have did some activity
- User
html css js code to track number of days passed since i have did some activity
- Assistant
html css js code to track number of days passed since i have did some activity
To create a simple web application that tracks the number of days passed since a specific activity, you can utilize HTML, CSS, and JavaScript. Below is an example implementation:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Activity Tracker</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Activity Tracker</h1>
<label for="activityDate">Select Activity Date:</label>
<input type="date" id="activityDate" />
<button id="calculateBtn">Calculate Days Passed</button>
<p id="result"></p>
</div>
<script src="script.js"></script>
</body>
</html>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
max-width: 400px;
margin: auto;
}
h1 {
text-align: center;
}
label {
display: block;
margin-bottom: 10px;
}
input[type="date"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
}
button {
padding: 10px 15px;
background-color: #5cb85c;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #4cae4c;
}
#result {
margin-top: 20px;
font-size: 20px;
text-align: center;
}
document.getElementById('calculateBtn').addEventListener('click', function () {
const activityDateInput = document.getElementById('activityDate').value;
if (!activityDateInput) {
alert("Please select a date.");
return;
}
const activityDate = new Date(activityDateInput);
const today = new Date();
// Calculate the difference in milliseconds
const timeDifference = today - activityDate;
// Convert the difference into days
const daysPassed = Math.floor(timeDifference / (1000 * 3600 * 24));
// Display the result
document.getElementById('result').textContent = `Days passed since the activity: ${daysPassed}`;
});
index.html, styles.css, and script.js.index.html in your web browser to see the activity tracker in action.Feel free to modify the styles and functionality to suit your preferences!