Skip to content
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
15 changes: 9 additions & 6 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<!DOCTYPE html>
<!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>
<title>Quote Generator App</title>
<link rel="stylesheet" href="style.css" />
<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>
<div class="quote-app">
<h1>hello there</h1>
<p id="quote" class="quote-text"></p>
<p id="author" class="quote-author"></p>
<button type="button" id="new-quote" class="quote-btn">New quote</button>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion Sprint-3/quote-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "quote-generator",
"version": "1.0.0",
"license": "CC-BY-SA-4.0",
"description": "You must update this package",
"description": "Simple quote generator app that displays a random quote and its author when the user clicks a button.",
"scripts": {
"test": "jest --config=../jest.config.js quote-generator"
},
Expand Down
51 changes: 51 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
function getRandomQuote(obj) {
const quoteEl = document.getElementById("quote");
const authorEl = document.getElementById("author");
if (!quoteEl || !authorEl) return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice that you ensure the elements exist before using them

quoteEl.innerText = obj.quote;
authorEl.innerText = obj.author;
}

function setupQuotes() {
getRandomQuote(pickFromArray(quotes));
const quoteBtn = document.getElementById("new-quote");
if (quoteBtn)
quoteBtn.addEventListener("click", () =>
getRandomQuote(pickFromArray(quotes))
);
}

// New DOM wiring using window.onload (replaces previous readiness block)
window.onload = () => {
const quoteText = document.getElementById("quote");
const authorText = document.getElementById("author");
const newQuoteBtn = document.getElementById("new-quote");
const autoPlayCheckbox = document.getElementById("auto-play");
const autoPlayStatus = document.getElementById("auto-play-txt");

let autoPlayInterval;

function generateQuote() {
const randomQuote = pickFromArray(quotes);
if (!randomQuote) return;
if (quoteText) quoteText.innerText = randomQuote.quote;
if (authorText) authorText.innerText = `- ${randomQuote.author}`;
}

generateQuote();

if (newQuoteBtn) newQuoteBtn.addEventListener("click", generateQuote);

if (autoPlayCheckbox) {
autoPlayCheckbox.addEventListener("change", (event) => {
if (event.target.checked) {
if (autoPlayStatus) autoPlayStatus.innerText = "Auto-Play: ON";
autoPlayInterval = setInterval(generateQuote, 5000);
} else {
if (autoPlayStatus) autoPlayStatus.innerText = "Auto-Play: OFF";
clearInterval(autoPlayInterval);
}
});
Comment on lines +39 to +48
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't see the autoplay checkbox on the web page

}
};

// DO NOT EDIT BELOW HERE

// pickFromArray is a function which will return one item, at
Expand Down
77 changes: 77 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,78 @@
/** Write your CSS in here **/
:root {
--mustard: #e6a918; /* main mustard */
--mustard-dark: #c58f00; /* darker for accents */
--panel: #ffffff;
--muted: #555555;
}

html,
body {
height: 100%;
margin: 0;
}

body {
font-family:
system-ui,
-apple-system,
"Segoe UI",
Roboto,
Helvetica,
Arial,
sans-serif;
background-color: var(--mustard);
display: flex;
align-items: center;
justify-content: center;
padding: 3rem 1rem;
}

.quote-app {
display: grid;
gap: 16px;
max-width: 900px;
width: 100%;
margin: 0 auto;
padding: 48px;
background-color: var(--panel);
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.quote-text {
font-size: 1.9rem;
line-height: 1.3;
margin: 0 0 16px;
color: var(--mustard-dark);
}

.quote-author {
font-size: 1rem;
color: var(--mustard-dark);
margin: 0 0 12px 0;
text-align: right;
}

.quote-btn {
justify-self: end;
padding: 10px 18px;
border-radius: 6px;
border: none;
background: var(--mustard-dark);
color: #fff;
cursor: pointer;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.12);
}
.quote-btn:focus {
outline: 3px solid rgba(197, 143, 0, 0.25);
}

/* small responsive tweak */
@media (max-width: 640px) {
.quote-text {
font-size: 1.25rem;
}
.quote-app {
padding: 24px;
}
}
Loading