Skip to content

50Projects-HTML-CSS-JavaScript : Pomodoro timer #47

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 22, 2024
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,19 @@ In order to run this project you need:
</details>
</li>

<li>
<details>
<summary>Pomodoro Timer</summary>
<p>The Productivity Timer (Pomodoro Timer) is a simple yet effective timer application based on the Pomodoro technique. It helps users stay productive by alternating between focus intervals (e.g., 5 minutes) and short breaks (e.g., 2 minutes). The app provides visual cues through animations and sound alerts to signal transitions between focus and break periods.

</p>
<ul>
<li><a href="https://tajulafreen.github.io/50Projects-HTML-CSS-JavaScript/Source-Code/PomodoroTimer/">Live Demo</a></li>
<li><a href="https://github.com/tajulafreen/50Projects-HTML-CSS-JavaScript/tree/main/Source-Code/PomodoroTimer">Source</a></li>
</ul>
</details>
</li>

</ol>

<p align="right">(<a href="#readme-top">back to top</a>)</p>
Expand Down
23 changes: 23 additions & 0 deletions Source-Code/PomodoroTimer/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Productivity Timer</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>Productivity Timer</h1>
<div class="timer-display">
<span id="minutes">25</span>:<span id="seconds">00</span>
</div>
<div class="controls">
<button id="start-btn">Start</button>
<button id="reset-btn">Reset</button>
</div>
<p id="status">Focus Session</p>
</div>
<script src="script.js"></script>
</body>
</html>
54 changes: 54 additions & 0 deletions Source-Code/PomodoroTimer/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const startBtn = document.getElementById('start-btn');
const resetBtn = document.getElementById('reset-btn');
const minutesDisplay = document.getElementById('minutes');
const secondsDisplay = document.getElementById('seconds');
const statusDisplay = document.getElementById('status');

let timerInterval;
let isFocusSession = true; // Start with a focus session
const focusTime = 5 * 60; // 5 minutes in seconds
const breakTime = 5 * 60; // 5 minutes in seconds
let timeRemaining = focusTime;

const updateDisplay = () => {
const minutes = Math.floor(timeRemaining / 60);
const seconds = timeRemaining % 60;
minutesDisplay.textContent = String(minutes).padStart(2, '0');
secondsDisplay.textContent = String(seconds).padStart(2, '0');
};

const toggleSession = () => {
isFocusSession = !isFocusSession;
timeRemaining = isFocusSession ? focusTime : breakTime;
statusDisplay.textContent = isFocusSession
? 'Focus Session'
: 'Break Session';
updateDisplay();
};

const startTimer = () => {
if (timerInterval) return; // Prevent multiple intervals
timerInterval = setInterval(() => {
if (timeRemaining > 0) {
timeRemaining -= 1;
updateDisplay();
} else {
clearInterval(timerInterval);
timerInterval = null;
toggleSession();
}
}, 1000);
};

const resetTimer = () => {
clearInterval(timerInterval);
timerInterval = null;
timeRemaining = isFocusSession ? focusTime : breakTime;
updateDisplay();
};

startBtn.addEventListener('click', startTimer);
resetBtn.addEventListener('click', resetTimer);

// Initialize display
updateDisplay();
51 changes: 51 additions & 0 deletions Source-Code/PomodoroTimer/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
body {
font-family: Arial, sans-serif;
background-color: #f0f4f8;
color: #333;
text-align: center;
margin: 0;
padding: 0;
}

.container {
max-width: 400px;
margin: 100px auto;
padding: 20px;
background: #fff;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

h1 {
margin-bottom: 20px;
}

.timer-display {
font-size: 3rem;
margin: 20px 0;
}

.controls button {
font-size: 1rem;
padding: 10px 20px;
margin: 5px;
border: none;
border-radius: 5px;
cursor: pointer;
}

#start-btn {
background-color: #28a745;
color: white;
}

#reset-btn {
background-color: #dc3545;
color: white;
}

#status {
font-size: 1.2rem;
margin-top: 20px;
color: #555;
}