Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
51 changes: 51 additions & 0 deletions NoveltyCalculator/Yasir761/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Age Calculator

![Age Calculator Screenshot](screenshot.png)

This Age Calculator is a web application that allows users to input their birth date and calculates their age in years, as well as in various novelty units, such as planetary years and fruit years.

## Features

- Calculate age in years based on the provided birth date.
- Convert age into novelty units for planets in our solar system and the average lifespan of certain fruits and vegetables.
- User-friendly interface with a responsive design for different screen sizes.

## Getting Started

These instructions will help you get a copy of the project up and running on your local machine.

### Prerequisites

- Web browser

### Installation

1. Clone the repository:

```bash
git clone https://github.com/javascripts-mini-projects.git

```

Navigate to the project directory:


```bash
cd NoveltyCalculator
```
Open the index.html file in your preferred web browser.

## Usage

Open the application in your web browser.
Enter your birth date in the provided input field.
Click the "Calculate" button.
Your age in years and novelty units will be displayed in the results section.
Built With
HTML, CSS, and JavaScript


## Authors

@Yasir761

Binary file added NoveltyCalculator/Yasir761/Screenshot .png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions NoveltyCalculator/Yasir761/Script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function calculateAge() {
const birthdateInput = document.getElementById('birthdate');
const ageInYearsElement = document.getElementById('age-in-years');
const noveltyUnitsList = document.getElementById('novelty-units');

const birthdate = new Date(birthdateInput.value);
const today = new Date();

const ageInMilliseconds = today - birthdate;
const ageInSeconds = ageInMilliseconds / 1000;
const ageInYears = ageInSeconds / (365 * 24 * 60 * 60);

ageInYearsElement.textContent = `Your age in years: ${ageInYears.toFixed(2)}`;

const planetaryYears = {
'Mercury': ageInYears / 0.2408467,
'Venus': ageInYears / 0.61519726,
'Mars': ageInYears / 1.8808158,
'Jupiter': ageInYears / 11.862615,
'Saturn': ageInYears / 29.447498,
'Uranus': ageInYears / 84.016846,
'Neptune': ageInYears / 164.79132
};

const fruitYears = {
'Apple': ageInYears / 80,
'Banana': ageInYears / 25,
'Carrot': ageInYears / 2,
'Grape': ageInYears / 60,
'Watermelon': ageInYears / 90
};

noveltyUnitsList.innerHTML = '';

for (const planet in planetaryYears) {
const listItem = document.createElement('li');
listItem.textContent = `${planet}: ${planetaryYears[planet].toFixed(2)} years`;
noveltyUnitsList.appendChild(listItem);
}

for (const fruit in fruitYears) {
const listItem = document.createElement('li');
listItem.textContent = `${fruit}: ${fruitYears[fruit].toFixed(2)} years`;
noveltyUnitsList.appendChild(listItem);
}
}
89 changes: 89 additions & 0 deletions NoveltyCalculator/Yasir761/Style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* Reset some default styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: 'Arial', sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}

.container {
background-color: #ffffff;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
max-width: 400px;
width: 90%;
text-align: center;
padding: 20px;
}

h1 {
font-size: 28px;
color: #333;
margin-bottom: 20px;
}

.label {
font-size: 18px;
color: #333;
display: block;
text-align: left;
margin-top: 15px;
}

.input-field {
width: 100%;
padding: 10px;
margin-top: 8px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}

.button {
background-color: #007bff;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
font-size: 18px;
cursor: pointer;
}

.results {
margin-top: 30px;
}

.results h2 {
font-size: 24px;
margin-bottom: 10px;
}

.results ul {
list-style-type: none;
padding: 0;
}

.results li {
font-size: 16px;
margin: 5px 0;
color: #333;
}

/* Responsive design */

@media screen and (max-width: 768px) {
.container {
padding: 15px;
}
}
26 changes: 26 additions & 0 deletions NoveltyCalculator/Yasir761/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Age Calculator</title>
<link rel="stylesheet" href="Style.css"> <!-- Include the CSS file -->
</head>
<body>
<div class="container">
<h1>Age Calculator</h1>
<div class="input-container">
<label for="birthdate" class="label">Enter your birth date:</label>
<input type="date" id="birthdate" class="input-field">
<button onclick="calculateAge()" class="button">Calculate</button>
</div>
<div class="results">
<h2>Your age:</h2>
<p id="age-in-years" class="result"></p>
<h2>Your age in novelty units:</h2>
<ul id="novelty-units" class="result"></ul>
</div>
</div>
<script src="Script.js"></script> <!-- Include the JavaScript file -->
</body>
</html>