Skip to content

Commit 65719b4

Browse files
Alex JamshidiAlex Jamshidi
authored andcommitted
all tests pass
1 parent 99861f2 commit 65719b4

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎Sprint-3/quote-generator/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<script defer src="quotes.js"></script>
88
</head>
99
<body>
10-
<h1>hello there</h1>
10+
<h1>Random Quote:</h1>
1111
<p id="quote"></p>
1212
<p id="author"></p>
1313
<button type="button" id="new-quote">New quote</button>

‎Sprint-3/quote-generator/quotes.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,34 @@ const quotes = [
491491
];
492492

493493
// call pickFromArray with the quotes array to check you get a random quote
494+
495+
function setup() {
496+
updateQuote();
497+
appendQuote();
498+
}
499+
500+
const state = {
501+
quote: "",
502+
author: "",
503+
};
504+
505+
function updateQuote() {
506+
const chosenQuote = pickFromArray(quotes);
507+
state.quote = chosenQuote.quote;
508+
state.author = chosenQuote.author;
509+
}
510+
511+
function appendQuote() {
512+
const quoteElem = document.getElementById("quote");
513+
const authorElem = document.getElementById("author");
514+
quoteElem.textContent = "";
515+
authorElem.textContent = "";
516+
quoteElem.append(state.quote);
517+
authorElem.append(state.author);
518+
}
519+
520+
document.getElementById("new-quote").addEventListener("click", function () {
521+
setup();
522+
});
523+
524+
window.onload = setup;

0 commit comments

Comments
 (0)