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
18 changes: 14 additions & 4 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
<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>
<h1>Quote Generator</h1>
<div class="quote-box">
<p id="quote"></p>
<p id="author"></p>
</div>
<button type="button" id="new-quote">New quote</button>
<div id="autoplay-controls">
<label>
<input type="checkbox" id="autoplay-toggle" />
Auto-play
</label>
<p id="autoplay-status">auto-play:OFF</p>
</div>
</body>
</html>
63 changes: 63 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,66 @@ const quotes = [
];

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

const quoteP = document.querySelector("#quote");
const authorP = document.querySelector("#author");
const newQuoteBtn = document.querySelector("#new-quote");
const autoplayToggle = document.querySelector("#autoplay-toggle");
const autoplayStatus = document.querySelector("#autoplay-status");

let autoplayId = null;
let currentQuote = null;

// Picks and displays a random quote, avoiding the same quote twice in a row.
function showRandomQuote() {
let randomQuote = pickFromArray(quotes);

if (quotes.length > 1) {
while (randomQuote === currentQuote) {
randomQuote = pickFromArray(quotes);
}
}

currentQuote = randomQuote;
quoteP.innerText = randomQuote.quote;
authorP.innerText = randomQuote.author;
}

// Updates the status text to reflect whether auto-play is on or off.
function setAutoplayStatus(isEnabled) {
autoplayStatus.innerText = isEnabled ? "auto-play:ON" : "auto-play:OFF";
}

// Starts auto-play and immediately shows a new quote as user feedback.
function startAutoplay() {
if (autoplayId !== null) {
clearInterval(autoplayId);
}

showRandomQuote();
autoplayId = setInterval(showRandomQuote, 60000);
setAutoplayStatus(true);
}

// Stops auto-play if it is running and updates the status text.
function stopAutoplay() {
if (autoplayId !== null) {
clearInterval(autoplayId);
autoplayId = null;
}
setAutoplayStatus(false);
}

// Handles checkbox changes to start or stop auto-play.
function handleAutoplayToggle() {
if (autoplayToggle.checked) {
startAutoplay();
} else {
stopAutoplay();
}
}

showRandomQuote();
newQuoteBtn.addEventListener("click", showRandomQuote);
autoplayToggle.addEventListener("change", handleAutoplayToggle);
setAutoplayStatus(false);
75 changes: 75 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,76 @@
/** Write your CSS in here **/
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
padding: 40px;
font-family: Helvetica, sans-serif;
background: #cc5500;
}

.container {
width: 100%;
max-width: 650px;
background: #cc5500;
padding: 50px;
border-radius: 8px;
}

h1 {
font-size: 26px;
line-height: 1.5;
color: white;
margin: 0;
text-align: center;
}

.quote-box {
width: 100%;
max-width: 700px;
background: white;
padding: 30px;
border-radius: 6px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
margin-bottom: 20px;
}

#quote {
font-size: 26px;
line-height: 1.5;
color: #222;
margin: 0;
text-align: center;
}

#author {
margin-top: 20px;
text-align: right;
color: #333;
font-weight: 600;
}

#new-quote {
margin-top: 2px;
background: white;
color: black;
border: 2px solid #cc5500;;
padding: 10px 18px;
cursor: pointer;
border-radius: 4px;
}

#autoplay-controls {
margin-top: 14px;
color: white;
text-align: center;
}

#autoplay-status {
margin: 8px 0 0;
}

* {
box-sizing: border-box;
}

Loading