generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
Elfredah
wants to merge
1
commit into
CodeYourFuture:main
Choose a base branch
from
Elfredah:Quote-Generator-App
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should use the quotes included in |
||
|
||
// 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?