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
13 changes: 10 additions & 3 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>
<title>Quote Generator</title>
<link rel="stylesheet" href="style.css" />
<script defer src="quotes.js"></script>
</head>
<body>
<h1>hello there</h1>
<h1>Quote Generator</h1>
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>

<div class="autoplay-container">
<input type="checkbox" id="auto-play" />
<label for="auto-play">Enable Auto-Play</label>
<p id="auto-play-txt">Auto-Play: OFF</p>
</div>
</body>
</html>
</html>
31 changes: 31 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,34 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote
const newQuote = document.querySelector("#new-quote");
const quoteTxt = document.querySelector("#quote");
const quoteAuthor = document.querySelector("#author");
const autoPlay = document.querySelector("#auto-play");
const autoPlayTxt = document.querySelector("#auto-play-txt");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On the html page I don't see any button to start autoplay

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

updated the code with md file requirement to toggle on/off and show quotes every 60 sec.

const autoPlayTime = 60000;
let autoPlayInterval = null;

newQuote.addEventListener("click", displayQuote);

autoPlay.addEventListener("change", () => {
if (autoPlay.checked) {
autoPlayTxt.textContent = "auto-play:ON";
autoPlayInterval = setInterval(displayQuote, autoPlayTime);
} else {
autoPlayTxt.textContent = "auto-play:OFF";
clearInterval(autoPlayInterval);
}
});

initaliseSite();

function initaliseSite() {
displayQuote();
}

function displayQuote() {
const quote = pickFromArray(quotes);
quoteTxt.textContent = quote.quote;
quoteAuthor.textContent = `- ${quote.author}`;
}
22 changes: 22 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
/** Write your CSS in here **/
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 20px;
background-color: aqua;
}
#quote {
font-size: 1.5em;
margin: 20px 0;
border: #160303 3px dotted;
}
#author {
font-size: 1.2em;
color: #555;
margin-bottom: 20px;
}
button {
padding: 10px 20px;
font-size: 1em;
cursor: pointer;
background-color: aquamarine;
}
Loading