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
5 changes: 3 additions & 2 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<!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>
<script defer src="quotes.js"></script>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>hello there</h1>
Expand Down
38 changes: 38 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,41 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote

const quoteElement = document.querySelector("#quote");
const authorElement = document.querySelector("#author");
const newQuoteButton = document.querySelector("#new-quote");

// function displayRandomQuote() {
// const randomQuote = pickFromArray(quotes);
// quoteElement.textContent = randomQuote.quote;
// authorElement.textContent = randomQuote.author;
// }

const AUTO_INTERVAL_MS = 6000;
let autoQuoteInterval = null;

function displayRandomQuote() {
const randomQuote = pickFromArray(quotes);
quoteElement.textContent = randomQuote.quote;
authorElement.textContent = randomQuote.author;
}

function startAutoQuotes(fetchFn) {
if (autoQuoteInterval) {
clearInterval(autoQuoteInterval);
}
autoQuoteInterval = setInterval(() => {
fetchFn();
}, AUTO_INTERVAL_MS);
}

// Display an initial random quote when the page loads
displayRandomQuote();
startAutoQuotes(displayRandomQuote);

// Display a new quote on click and reset the auto-timer
newQuoteButton.addEventListener("click", () => {
displayRandomQuote();
startAutoQuotes(displayRandomQuote);
});
51 changes: 51 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
/** Write your CSS in here **/
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}

body {
max-width: 48rem;
padding: 2rem;
font-family:
system-ui,
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
sans-serif;
background: #ffffff;
color: #111827;
line-height: 1.5;
}

h1 {
margin-bottom: 1rem;
font-size: 2rem;
}

#quote {
margin-bottom: 0.75rem;
font-size: 1.2rem;
}

#author {
margin-bottom: 1.5rem;
color: #4b5563;
font-style: italic;
}

#new-quote {
padding: 0.55rem 1.1rem;
border: 1px solid #d1d5db;
border-radius: 0.4rem;
background: #888;
color: #111827;
font-size: 0.95rem;
cursor: pointer;
}

#new-quote:hover {
background: #ffffff;
}
Loading