Skip to content

Commit

Permalink
Added Digital Detox Calculator (#1229)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishaprasad authored Jun 11, 2024
1 parent cf844fa commit f601e93
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Calculators/Digital-Detox-Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# <p align="center">Digital Detox Calculator</p>

## Description :-

Calculates the amount of time we spend on digital devices and suggests a plan for a balanced digital detox.

## Tech Stacks :-

- HTML
- CSS
- JavaScript

## Screenshots :-

![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/40f2d1e3-9598-4f9f-9ff3-1e20fb30b7e4)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions Calculators/Digital-Detox-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Digital Detox Calculator</title>
</head>
<body>
<div class="main-container">
<img src="assets/left-image.jpg" alt="Left Image" class="side-image">
<div class="container">
<h1>Digital Detox Calculator</h1>
<form id="detoxForm">
<div class="form-group">
<label for="hoursSpent">Hours spent on devices daily:</label>
<input type="number" id="hoursSpent" required>
</div>
<div class="form-group">
<label for="daysPerWeek">Days per week:</label>
<input type="number" id="daysPerWeek" required>
</div>
<button type="button" onclick="calculateDetox()">Calculate</button>
</form>
<div id="result"></div>
</div>
<img src="assets/right-image.jpg" alt="Right Image" class="side-image">
</div>
<script src="script.js"></script>
</body>
</html>

25 changes: 25 additions & 0 deletions Calculators/Digital-Detox-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function calculateDetox() {
const hoursSpent = parseFloat(document.getElementById('hoursSpent').value);
const daysPerWeek = parseFloat(document.getElementById('daysPerWeek').value);
const resultDiv = document.getElementById('result');

if (isNaN(hoursSpent) || isNaN(daysPerWeek) || hoursSpent <= 0 || daysPerWeek <= 0) {
resultDiv.innerHTML = "<p>Please enter valid inputs.</p>";
return;
}

const weeklyUsage = hoursSpent * daysPerWeek;
const monthlyUsage = weeklyUsage * 4;
const yearlyUsage = weeklyUsage * 52;

const detoxRecommendation = hoursSpent > 5 ? "Consider reducing your daily screen time gradually." :
hoursSpent > 3 ? "Your screen time is moderate, but it's good to take regular breaks." :
"Your screen time is within healthy limits.";

resultDiv.innerHTML = `
<p><strong>Weekly Device Usage:</strong> ${weeklyUsage.toFixed(2)} hours</p>
<p><strong>Monthly Device Usage:</strong> ${monthlyUsage.toFixed(2)} hours</p>
<p><strong>Yearly Device Usage:</strong> ${yearlyUsage.toFixed(2)} hours</p>
<p>${detoxRecommendation}</p>
`;
}
95 changes: 95 additions & 0 deletions Calculators/Digital-Detox-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(to right, #246d8a, #cc65cf);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

.main-container {
display: flex;
align-items: center;
justify-content: center;
width: 90%;
height: 90%;
}

.side-image {
flex: 1;
max-width: 25%;
height: 100%;
object-fit: cover;
margin: 0 60px;
border-radius: 4%;
transition: transform 0.3s ease, filter 0.3s ease;
}

.side-image:hover{
transform: scale(1.05);
filter: brightness(1.1);
}
.container {
background-color: #ffffff;
padding: 25px 30px;
border-radius: 10px;
box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1);
width: 60%;
max-width: 450px;
text-align: center;
z-index: 1;
}

h1 {
font-size: 28px;
margin-bottom: 25px;
color: #00796b;
}

.form-group {
margin-bottom: 20px;
text-align: left;
}

label {
display: block;
margin-bottom: 8px;
font-weight: bold;
color: #004d40;
}

input {
width: calc(100% - 20px);
padding: 10px;
border: 1px solid #b0bec5;
border-radius: 5px;
outline: none;
font-size: 16px;
}

input:focus {
border-color: #4db6ac;
}

button {
background-color: #00796b;
color: white;
padding: 10px 25px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}

button:hover {
background-color: #004d40;
}

#result {
margin-top: 25px;
font-size: 18px;
color: #004d40;
line-height: 1.5;
}
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,20 @@ <h3>Evaluates derivatives and mathematical functions.</h3>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Digital Detox Calculator</h2>
<h3>Calculates the amount of time we spend on digital devices and suggests a plan for a balanced digital detox.</h3>
<div class="card-footer">
<a href="./Calculators/Digital-Detox-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Digital-Detox-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
<div class="box">
<div class="content">
<h2>Disarium Number Calculator</h2>
Expand Down

0 comments on commit f601e93

Please sign in to comment.