Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8bc3e8c
feat: add container for quotes
Grajales-K Apr 7, 2026
c8b9d48
feat: add stylesheet and background styling for quote generator
Grajales-K Apr 7, 2026
43a7d8e
feat: add media images and sound
Grajales-K Apr 7, 2026
8291f6f
refactor: move example image to assets
Grajales-K Apr 7, 2026
4841426
feat: add script.js for additional functionality in quote generator
Grajales-K Apr 13, 2026
62c26cc
feat: implement random quote generation functionality
Grajales-K Apr 13, 2026
fcf0c91
feat: add auto-play functionality for random quotes
Grajales-K Apr 13, 2026
0d91e68
feat: add background sound playback functionality
Grajales-K Apr 13, 2026
c72fb1b
feat: enhance quote generator with sound playback and auto-quote inte…
Grajales-K Apr 13, 2026
ee8e66d
refactor: remove unused pickFromArray function from quotes.js
Grajales-K Apr 13, 2026
7847481
feat: add autoplay functionality for background sound and improve quo…
Grajales-K Apr 14, 2026
81bbb7f
feat: update styles for quote generator with improved layout and design
Grajales-K Apr 14, 2026
6d68eaa
feat: add button for auto-quote playback in quote generator
Grajales-K Apr 14, 2026
c7538f3
feat: rename button for auto-quote playback and update event listener
Grajales-K Apr 14, 2026
f0185ee
feat: improve sound playback logic and enhance quote display layout
Grajales-K Apr 14, 2026
beb1440
Revert "feat: improve sound playback logic and enhance quote display …
Grajales-K Apr 14, 2026
4172f20
feat: update styles for quote generator with enhanced design and layo…
Grajales-K Apr 14, 2026
c14ea3a
feat: enhance quote generator with background sound playback and rand…
Grajales-K Apr 14, 2026
9375e10
feat: refactor quote generation logic and improve event handling for …
Grajales-K Apr 14, 2026
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
Binary file added Sprint-3/quote-generator/assets/SPACE.mp3
Binary file not shown.
Binary file added Sprint-3/quote-generator/assets/stars.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprint-3/quote-generator/assets/stars.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 12 additions & 5 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<link rel="stylesheet" href="style.css" />
<title>Quote generator app</title>
<script defer src="quotes.js"></script>
<script defer src="script.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>
<div id="container-quote">
<h1>Random Quotes 🔊</h1>
<p id="quote"></p>
<p id="author"></p>
<div class="buttons-wrapper">
<button type="button" id="new-quote">New quote</button>
<button type="button" id="playButton">Play Auto-Quotes</button>
</div>
</div>
</body>
</html>
7 changes: 3 additions & 4 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
// ---------------
// 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)];
}


// ========================= array quotes ======================

// A list of quotes you can use in your app.
// DO NOT modify this array, otherwise the tests may break!
Expand Down
89 changes: 89 additions & 0 deletions Sprint-3/quote-generator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// --- Configuration & Global Variables ---
const backgroundSound = new Audio("assets/SPACE.mp3");
let isSoundStarted = false; // Using 'let' as the value changes to true once music plays
let quoteInterval; // Using 'let' to store/clear the interval ID

// --- DOM Elements ---
const button = document.querySelector("#new-quote");
const secondButton = document.querySelector("#playButton");
const quoteText = document.querySelector("#quote");
const quoteAuthor = document.querySelector("#author");

// --- Logic Functions ---

/**
* Picks a random quote from the array and updates the DOM elements.
*/
function randomQuoteGenerate() {
if (typeof quotes !== "undefined") {
const randomArr = quotes[Math.floor(Math.random() * quotes.length)];
if (quoteText && quoteAuthor) {
quoteText.textContent = randomArr.quote;
quoteAuthor.textContent = randomArr.author;
}
}
}

/**
* Attempts to play the background audio if not in a test environment.
*/
function playSound() {
// Check for 'jsdom' to prevent errors during automated testing
if (!navigator.userAgent.includes("jsdom") && !isSoundStarted) {
backgroundSound
.play()
.then(() => {
isSoundStarted = true;
})
.catch(() =>
console.log("Waiting for user interaction to play audio...")
);
}
}

// --- Callbacks (Event Handler Functions) ---

/**
* Handles manual quote changes via button click.
*/
function changeQuote() {
randomQuoteGenerate();
playSound();
}

/**
* Toggles the automatic quote generator on or off.
*/
function toggleAutomaticQuote() {
if (quoteInterval) {
// Stop the interval if it's already running
clearInterval(quoteInterval);
quoteInterval = null;
secondButton.textContent = "Play Auto-Quotes";
} else {
// Start the interval and update every 2 seconds
randomQuoteGenerate();
quoteInterval = setInterval(randomQuoteGenerate, 2000);
secondButton.textContent = "Stop";
playSound();
}
}

// --- Initialization ---

/**
* Sets up the initial state and attaches event listeners once the window has loaded.
*/
window.addEventListener("load", () => {
// Generate the first quote immediately on load
randomQuoteGenerate();

// Attach event listeners to the buttons
if (button) {
button.addEventListener("click", changeQuote);
}

if (secondButton) {
secondButton.addEventListener("click", toggleAutomaticQuote);
}
});
82 changes: 81 additions & 1 deletion Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,81 @@
/** Write your CSS in here **/
body {
background-image: url("./assets/stars.webp");
background-size: cover;
background-position: center;
background-attachment: fixed;
margin: 0;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
font-family: Arial, sans-serif;
padding: 10px;
}

#container-quote {
background: rgba(0, 0, 0, 0.1);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
padding: 1.2rem;
border-radius: 15px;
border: 1px solid rgba(255, 255, 255, 0.15);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
width: 90%;
max-width: 300px;
min-height: auto;
display: flex;
flex-direction: column;
text-align: center;
}

h1 {
font-size: 1.1rem;
margin: 0 0 0.8rem 0;
color: #ffffff;
opacity: 0.9;
}

#quote {
font-size: 1.1rem;
font-style: italic;
color: #3bffeb;
line-height: 1.4;
margin-bottom: 0.5rem;
min-height: 50px;
display: flex;
align-items: center;
justify-content: center;
}

#author {
font-size: 0.8rem;
font-weight: bold;
color: #cbd5e0;
margin-bottom: 1.2rem;
}

.buttons-wrapper {
display: flex;
gap: 8px;
width: 100%;
}

#new-quote, #playButton {
flex: 1;
background-color: rgba(3, 251, 255, 0.1);
color: white;
border: 1px solid rgba(59, 255, 235, 0.3);
border-radius: 6px;
padding: 8px 10px;
font-size: 0.75rem;
font-family: Arial, sans-serif;
cursor: pointer;
transition: all 0.3s ease;
}

#new-quote:hover,
#playButton:hover {
background-color: #3bffeb;
color: #000593;
transform: translateY(-2px);
}
Loading