-
-
Notifications
You must be signed in to change notification settings - Fork 194
Glasgow | ITP-SEP-25 | Alaa Tagi | Sprint 3 | feature/quote-generator #890
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,16 @@ | |
| function pickFromArray(choices) { | ||
| return choices[Math.floor(Math.random() * choices.length)]; | ||
| } | ||
| function showRandomQuote() { | ||
| const randomQuote = pickFromArray(quotes); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can add condition after that is randomQuote is available or not, if not , then return |
||
| const quoteText = document.getElementById("quote-text"); | ||
| const quoteAuthor = document.getElementById("quote-author"); | ||
|
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During initial load, if the script runs before the DOM is ready, |
||
| quoteText.innerText = `"${randomQuote.quote}"`; | ||
| quoteAuthor.innerText = `- ${randomQuote.author}`; | ||
| } | ||
|
|
||
| window.onload = showRandomQuote; | ||
| document.getElementById("new-quote-button").addEventListener("click", showRandomQuote); | ||
|
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The button element might not exist during first load when the JS script runs before the DOM element is ready. If
Please wrap the event listener setup inside window.onload = function() { This ensures the DOM is fully loaded before accessing elements and prevents the TypeError. |
||
| // A list of quotes you can use in your app. | ||
| // DO NOT modify this array, otherwise the tests may break! | ||
| const quotes = [ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The quote-container element is not needed here