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>
47 changes: 47 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,50 @@ 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;

function showRandomQuote() {
const randomQuote = pickFromArray(quotes);
quoteP.innerText = randomQuote.quote;
authorP.innerText = randomQuote.author;
}

function setAutoplayStatus(isEnabled) {
autoplayStatus.innerText = isEnabled ? "auto-play:ON" : "auto-play:OFF";
}

function startAutoplay() {
if (autoplayId !== null) {
clearInterval(autoplayId);
}
autoplayId = setInterval(showRandomQuote, 60000);
setAutoplayStatus(true);
}

function stopAutoplay() {
if (autoplayId !== null) {
clearInterval(autoplayId);
autoplayId = null;
}
setAutoplayStatus(false);
}

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