Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
26 changes: 26 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,29 @@ const quotes = [
];

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

function chooseQuote() {
const randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

welldone you have done a good job just a few things:
can we make the line easy to understand research KISS and SOC and DRY. can we do something to avoid repeating the line 496? its used in line 20 too

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.

thank you


const quote = document.getElementById("quote");
quote.innerText = randomQuote.quote;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

can we use textContent instead of innerText and why ?
what happens if quote is null ?


const author = document.getElementById("author");
author.innerText = 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", () => {
if (autoGenerate.checked) {
interval = setInterval(chooseQuote, 2000);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

what doeas 2000 mean? what are magic numbers ? and how can we handle magic numbers ?

} 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