Skip to content
Closed
Show file tree
Hide file tree
Changes from 10 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
7 changes: 5 additions & 2 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<!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>
</head>
<body>
<label>
<input type="checkbox" id="auto-play-toggle" />Auto-generate
</label>
<h1>hello there</h1>
<p id="quote"></p>
<p id="author"></p>
Expand Down
30 changes: 30 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,33 @@ const quotes = [
];

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

function chooseQuote() {
const randomQuote = pickFromArray(quotes)

const quote = document.getElementById("quote");
if(quote!==null){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

please check spacing here and elsewhere, use the style guide as reference

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.

done

quote.textContent = randomQuote.quote;
}
const author = document.getElementById("author");
if(author!==null){
author.textContent = randomQuote.author;
}
}

window.addEventListener("load", chooseQuote);

const button = document.getElementById("new-quote");
button.addEventListener("click", chooseQuote);

const autoGenerate = document.getElementById("auto-play-toggle");
let interval = null;
autoGenerate.addEventListener("change", () => {
let changeQuoteInterval=2000
if (autoGenerate.checked) {
interval = setInterval(chooseQuote, changeQuoteInterval);
} else {
clearInterval(interval);
interval = null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this line may not be necessary, try removing it and see if it works?

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.

which line? the "if" starts the interval and without the "else" the interval doesn't stop even after the box is unchecked

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the line that this comment is on, line 521 which says interval = null;

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.

done

}
});
Loading