Skip to content

ITP JAN 2025/ELFREDAH KEVIN-ALERECHI/DAT GROUP/Quote Generator App #495

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 12 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
function setAlarm() {}
function setAlarm() {
const seconds = parseInt(document.getElementById("alarmTime").value, 10);

if (isNaN(seconds) || seconds < 0) {
alert("Please enter a valid number of seconds.");
return;
}

setTimeout(playAlarm, seconds * 1000);
}



// DO NOT EDIT BELOW HERE

Expand Down
111 changes: 94 additions & 17 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,97 @@
<!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>Title here</title>
</head>
<body>
<div class="centre">
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
<label for="alarmSet">Set time to:</label>
<input id="alarmSet" type="number" />

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
</div>
<script src="alarmclock.js"></script>
</body>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alarm Timer</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 20px;
}
#alarm-container {
margin-top: 50px;
}
#time-remaining {
font-size: 48px;
margin-bottom: 20px;
font-weight: bold;
}
#alarm-sound {
display: none;
}
</style>
</head>
<body>

<div id="time-remaining">00:00</div> <!-- Timer moved to the top -->
<div id="alarm-container">
<h1>Set Alarm</h1>
<input type="text" id="alarm-time" placeholder="Enter time in seconds">
<button onclick="setAlarm()">Set Alarm</button>
<button id="stop-alarm" onclick="stopAlarm()" style="display: none;">Stop Alarm</button>
<audio id="alarm-sound" src="https://www.soundjay.com/button/beep-07.wav" loop></audio>
</div>

<script>
let timer;
let timeRemaining;
let alarmSound = document.getElementById('alarm-sound');
let stopButton = document.getElementById('stop-alarm');
let timeRemainingTitle = document.getElementById('time-remaining');

// Function to format time in mm:ss
function formatTime(seconds) {
let minutes = Math.floor(seconds / 60);
let remainingSeconds = seconds % 60;
return `${minutes < 10 ? '0' + minutes : minutes}:${remainingSeconds < 10 ? '0' + remainingSeconds : remainingSeconds}`;
}

// Function to set the alarm
function setAlarm() {
const alarmTime = parseInt(document.getElementById('alarm-time').value);
if (isNaN(alarmTime) || alarmTime <= 0) return; // Validate input

timeRemaining = alarmTime;
timeRemainingTitle.innerText = formatTime(timeRemaining);
stopButton.style.display = 'inline';

// Start countdown
if (timer) clearInterval(timer); // Clear any previous timers
timer = setInterval(() => {
timeRemaining--;
timeRemainingTitle.innerText = formatTime(timeRemaining);
if (timeRemaining <= 0) {
clearInterval(timer);
playAlarm();
}
}, 1000);
}

// Function to play the alarm sound
function playAlarm() {
alarmSound.play(); // Play sound
document.body.style.backgroundColor = '#ffcccc'; // Change background color
stopButton.style.display = 'inline'; // Show stop button
}

// Function to stop the alarm sound
function stopAlarm() {
alarmSound.pause();
alarmSound.currentTime = 0;
document.body.style.backgroundColor = ''; // Reset background color
stopButton.style.display = 'none'; // Hide stop button
}

// Initialize when the page first loads
window.onload = function () {
timeRemainingTitle.innerText = '00:00';
alarmSound.pause();
alarmSound.currentTime = 0;
stopButton.style.display = 'none';
};
</script>

</body>
</html>
6 changes: 3 additions & 3 deletions Sprint-3/alarmclock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/CodeYourFuture/CYF-Coursework-Template.git"
"url": "git+https://github.com/Elfredah?tab=repositories"
},
"bugs": {
"url": "https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
"url": "https://github.com/issues/assigned"
},
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
"homepage": "https://github.com/users/Elfredah/projects/4",
"devDependencies": {
"@testing-library/dom": "^8.19.0",
"@testing-library/jest-dom": "^5.16.5",
Expand Down
134 changes: 122 additions & 12 deletions Sprint-3/quote-generator/index.html
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the JS code to a separate .js file?

Original file line number Diff line number Diff line change
@@ -1,15 +1,125 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<script defer src="quotes.js"></script>
</head>
<body>
<h1>hello there</h1>
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
</body>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Quote Generator</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}

#quote-container {
font-size: 24px;
margin-bottom: 20px;
padding: 20px;
border: 2px solid #333;
background-color: #f4f4f4;
display: inline-block;
max-width: 500px;
text-align: center;
}

#quote {
font-style: italic;
margin-bottom: 10px;
padding: 10px;
border: 2px dashed #333;
background-color: #fff;
font-size: 26px;
}

#author {
font-size: 20px;
color: #555;
padding: 10px;
border: 2px solid #333;
background-color: #e0e0e0;
}

button {
font-size: 18px;
padding: 10px 20px;
margin-top: 20px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}

button:hover {
background-color: #45a049;
}
</style>
</head>
<body>

<div id="quote-container">
<p id="quote">"Your quote will appear here."</p>
<p id="author">- Author</p>
</div>

<button onclick="displayRandomQuote()">Get Random Quote</button>

<script>
// DO NOT EDIT BELOW HERE

// pickFromArray is a function which will return one item, at
// random, from the given array.
//
// Parameters
// ----------
// choices: an array of items to pick from.
//
// Returns
// -------
// One item at random from the given array.
//
// Examples of use
// ---------------
// pickFromArray(['a','b','c','d']) // maybe returns 'c'

// You don't need to change this function
function pickFromArray(choices) {
return choices[Math.floor(Math.random() * choices.length)];
}

// A list of quotes you can use in your app.
// DO NOT modify this array, otherwise the tests may break!
const quotes = [
{
quote: "Life isn't about getting and having, it's about giving and being.",
author: "Kevin Kruse",
},
{
quote: "Whatever the mind of man can conceive and believe, it can achieve.",
author: "Napoleon Hill",
},
{
quote: "Strive not to be a success, but rather to be of value.",
author: "Albert Einstein",
},
{
quote:
"Two roads diverged in a wood, and I—I took the one less traveled by, And that has made all the difference.",
author: "Robert Frost",
},
{
quote: "I attribute my success to this: I never gave or took any excuse.",
author: "Florence Nightingale",
},
// Add more quotes here if needed
];
Comment on lines +91 to +114
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should use the quotes included in quotes.js.


// Function to display a random quote
function displayRandomQuote() {
const randomQuote = pickFromArray(quotes); // Pick a random quote from the array
document.getElementById('quote').innerText = `"${randomQuote.quote}"`; // Display the quote with quotation marks
document.getElementById('author').innerText = `- ${randomQuote.author}`; // Display the author
}
</script>

</body>
</html>
8 changes: 4 additions & 4 deletions Sprint-3/quote-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
"name": "quote-generator",
"version": "1.0.0",
"license": "CC-BY-SA-4.0",
"description": "You must update this package",
"description": "Updated package",
"scripts": {
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/CodeYourFuture/CYF-Coursework-Template.git"
"url": "git+https://github.com/Elfredah?tab=repositories"
},
"bugs": {
"url": "https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
"url": "https://github.com/issues/assigned"
},
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
"homepage": "https://github.com/users/Elfredah/projects/4",
"devDependencies": {
"@testing-library/dom": "^8.19.0",
"@testing-library/jest-dom": "^5.16.5",
Expand Down
File renamed without changes.
Loading