-
-
Notifications
You must be signed in to change notification settings - Fork 286
London | 26-ITP-May | Alex Jamshidi | Sprint 3 | Quote Generator App #1229
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 1 commit
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 |
|---|---|---|
|
|
@@ -491,3 +491,34 @@ const quotes = [ | |
| ]; | ||
|
|
||
| // call pickFromArray with the quotes array to check you get a random quote | ||
|
|
||
| function setup() { | ||
| updateQuote(); | ||
| appendQuote(); | ||
| } | ||
|
|
||
| const state = { | ||
| quote: "", | ||
| author: "", | ||
| }; | ||
|
|
||
| function updateQuote() { | ||
| const chosenQuote = pickFromArray(quotes); | ||
| state.quote = chosenQuote.quote; | ||
| state.author = chosenQuote.author; | ||
| } | ||
|
|
||
| function appendQuote() { | ||
| const quoteElem = document.getElementById("quote"); | ||
| const authorElem = document.getElementById("author"); | ||
| quoteElem.textContent = ""; | ||
| authorElem.textContent = ""; | ||
| quoteElem.append(state.quote); | ||
|
Member
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. This works, but you could also directly set quoteElem.textContent = state.quotewhich may be more clear as to your intent when reading, and may avoid a brief flash of an empty quote in the middle.
Author
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. instead of resetting .textcontent to "" and appending new quote/author, replaced quote/author directly with .textcontent |
||
| authorElem.append(state.author); | ||
| } | ||
|
|
||
| document.getElementById("new-quote").addEventListener("click", function () { | ||
| setup(); | ||
|
Member
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.
Personally I'd probably just have one function in file:
Author
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. renamed function to showNewQuote |
||
| }); | ||
|
|
||
| window.onload = setup; | ||
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.
Append isn't the most clear name here - it suggests that each time you call it an additional quote will be added to the page, rather than replacing the existing quote.
(Even though you implementation does use
appendinternally, the effect of the function isn't to append something to the page).Can you think of a more clear name?
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.
renamed to replaceQuote