From 93bf6fcfe78fe2932c65b142189d5af4711dd01b Mon Sep 17 00:00:00 2001 From: Ashwini Gurbaxani <98401812+gurbaxani@users.noreply.github.com> Date: Sun, 15 Sep 2024 12:09:35 +0530 Subject: [PATCH] Add timer functionality --- index.html | 10 +++--- script.js | 93 +++++++++++++++++++++++++++++++++++------------------- styles.css | 4 ++- 3 files changed, 69 insertions(+), 38 deletions(-) diff --git a/index.html b/index.html index 240bfad..31be7da 100644 --- a/index.html +++ b/index.html @@ -9,11 +9,6 @@

Improv Practice

-
- -
00:00
- -

Give me a random...

@@ -29,6 +24,11 @@

Improv Practice

Click a button to get a suggestion
+
+ +
00:00
+ +
diff --git a/script.js b/script.js index 66b9dae..325d836 100644 --- a/script.js +++ b/script.js @@ -1,37 +1,16 @@ document.addEventListener('DOMContentLoaded', function () { + // Elements for random suggestions const resultDiv = document.getElementById('result'); - - // Arrays for each category - const objects = [ - 'Book', 'Chair', 'Laptop', 'Pen', 'Phone', 'Sock', 'Table', 'Umbrella', 'Wallet', 'Watch' - ]; - const relationships = [ - 'Friend', 'Parent', 'Sibling', 'Colleague', 'Neighbor', 'Partner', 'Mentor', 'Student', 'Boss', 'Customer' - ]; - const locations = [ - 'Park', 'Library', 'Beach', 'Restaurant', 'Office', 'Airport', 'Museum', 'Mall', 'Gym', 'Mountain' - ]; - const occupations = [ - 'Teacher', 'Engineer', 'Artist', 'Chef', 'Doctor', 'Writer', 'Musician', 'Scientist', 'Farmer', 'Nurse' - ]; - const alphabets = [ - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' - ]; - const phrases = [ - 'Break a leg', 'Hit the nail on the head', 'Under the weather', 'Piece of cake', 'Let the cat out of the bag', 'Once in a blue moon', 'Bite the bullet', 'Spill the beans', 'Cost an arm and a leg', 'Hit the sack' - ]; - const emotions = [ - 'Happy', 'Sad', 'Angry', 'Excited', 'Confused', 'Nervous', 'Bored', 'Relieved', 'Surprised', 'Frustrated' - ]; - const genres = [ - 'Comedy', 'Drama', 'Horror', 'Romance', 'Action', 'Sci-Fi', 'Fantasy', 'Mystery', 'Thriller', 'Documentary' - ]; - const quirks = [ - 'Obsessive', 'Clumsy', 'Eccentric', 'Perfectionist', 'Shy', 'Talkative', 'Stubborn', 'Generous', 'Impulsive', 'Quiet' - ]; - const superpowers = [ - 'Telepathy', 'Invisibility', 'Super strength', 'Flight', 'Telekinesis', 'Time travel', 'Shape-shifting', 'Healing', 'Teleportation', 'Mind control' - ]; + const objects = ['Book', 'Chair', 'Laptop', 'Pen', 'Phone', 'Sock', 'Table', 'Umbrella', 'Wallet', 'Watch']; + const relationships = ['Friend', 'Parent', 'Sibling', 'Colleague', 'Neighbor', 'Partner', 'Mentor', 'Student', 'Boss', 'Customer']; + const locations = ['Park', 'Library', 'Beach', 'Restaurant', 'Office', 'Airport', 'Museum', 'Mall', 'Gym', 'Mountain']; + const occupations = ['Teacher', 'Engineer', 'Artist', 'Chef', 'Doctor', 'Writer', 'Musician', 'Scientist', 'Farmer', 'Nurse']; + const alphabets = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; + const phrases = ['Break a leg', 'Hit the nail on the head', 'Under the weather', 'Piece of cake', 'Let the cat out of the bag', 'Once in a blue moon', 'Bite the bullet', 'Spill the beans', 'Cost an arm and a leg', 'Hit the sack']; + const emotions = ['Happy', 'Sad', 'Angry', 'Excited', 'Confused', 'Nervous', 'Bored', 'Relieved', 'Surprised', 'Frustrated']; + const genres = ['Comedy', 'Drama', 'Horror', 'Romance', 'Action', 'Sci-Fi', 'Fantasy', 'Mystery', 'Thriller', 'Documentary']; + const quirks = ['Obsessive', 'Clumsy', 'Eccentric', 'Perfectionist', 'Shy', 'Talkative', 'Stubborn', 'Generous', 'Impulsive', 'Quiet']; + const superpowers = ['Telepathy', 'Invisibility', 'Super strength', 'Flight', 'Telekinesis', 'Time travel', 'Shape-shifting', 'Healing', 'Teleportation', 'Mind control']; // Function to set a random item from a given array to resultDiv function setRandomResult(array) { @@ -50,4 +29,54 @@ document.addEventListener('DOMContentLoaded', function () { document.getElementById('genre-btn').addEventListener('click', () => setRandomResult(genres)); document.getElementById('quirk-btn').addEventListener('click', () => setRandomResult(quirks)); document.getElementById('superpower-btn').addEventListener('click', () => setRandomResult(superpowers)); + + // Timer functionality + const startButton = document.getElementById('start-timer'); + const stopButton = document.getElementById('stop-timer'); + const timerDisplay = document.getElementById('timer-display'); + + let timer; + let seconds = 0; + let isRunning = false; + stopButton.disabled = true; + + function updateDisplay() { + const minutes = Math.floor(seconds / 60); + const secs = seconds % 60; + timerDisplay.textContent = `${String(minutes).padStart(2, '0')}:${String(secs).padStart(2, '0')}`; + } + + function startTimer() { + if (!isRunning) { + isRunning = true; + stopButton.disabled = false; + startButton.disabled = true; + stopButton.textContent = '✋ Stop'; + timer = setInterval(() => { + seconds++; + updateDisplay(); + }, 1000); + } + } + + function stopOrResetTimer() { + if (isRunning) { + clearInterval(timer); + isRunning = false; + startButton.disabled = false; // Enable the start button when stopped + stopButton.textContent = '🔄 Reset'; // Change text to Reset + } else { + // Reset the timer + seconds = 0; + updateDisplay(); + stopButton.disabled = true; + stopButton.textContent = '✋ Stop'; // Change text back to Stop + } + } + + startButton.addEventListener('click', startTimer); + stopButton.addEventListener('click', stopOrResetTimer); + + // Initial display update for the timer + updateDisplay(); }); diff --git a/styles.css b/styles.css index 01c5336..3a0a16f 100644 --- a/styles.css +++ b/styles.css @@ -5,9 +5,10 @@ } .timer-container { + position: fixed; + bottom: 20px; display: flex; align-items: center; - margin-bottom: 20px; } .timer-display { @@ -19,3 +20,4 @@ .nav-button { margin: 5px; } +