Skip to content

Sheffield|May-2025|Sheida Shabankari|Module-Data -Groups| Sprint-3|Quote generator #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
<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>
</head>
<body>
<h1>hello there</h1>
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
<input type="checkbox" id="auto-play"/><label id="auto-play-label">auto-play : OFF</label>
</body>
</html>
27 changes: 27 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// DO NOT EDIT BELOW HERE

// pickFromArray is a function which will return one item, at
Expand Down Expand Up @@ -491,3 +492,29 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote
function pickAndDisplayQuote() {
const randomQuote = pickFromArray(quotes);
//console.log(randomQuote);
document.getElementById("quote").textContent = randomQuote.quote;
document.getElementById("author").textContent = randomQuote.author;
}

document.getElementById("new-quote").addEventListener("click", () => {
pickAndDisplayQuote();
});
let intervalId;
document.getElementById("auto-play").addEventListener("change",(event)=>{
if (event.target.checked){
//console.log("auto-play is on");
document.getElementById("auto-play-label").textContent = "auto-play : ON";
intervalId=setInterval(pickAndDisplayQuote,5000);
}else{
document.getElementById("auto-play-label").textContent = "auto-play : OFF";
clearInterval(intervalId);
}
});
Comment on lines +506 to +515
Copy link
Contributor

Choose a reason for hiding this comment

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

Can probably insert some space around operators and punctuations in the code at lines 506-511 to improve their readability (like what you did in lines 495-500).





window.onload = pickAndDisplayQuote;