Skip to content

Commit 6812c93

Browse files
committed
wrote a function for quote-generator
1 parent 4222cda commit 6812c93

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Title here</title>
6+
<title>Quote-Generator</title>
77
<script defer src="quotes.js"></script>
88
</head>
99
<body>

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414
// Examples of use
1515
// ---------------
1616
// pickFromArray(['a','b','c','d']) // maybe returns 'c'
17+
function pickFromArray(choices) {
18+
return choices[Math.floor(Math.random() * choices.length)];
19+
}
20+
function quotesAndAuthor() {
21+
const randomQuote = pickFromArray(quotes);
22+
document.querySelector("#quote").innerText = randomQuote.quote;
23+
document.querySelector("#author").innerText = randomQuote.author;
24+
}
25+
function setup() {
26+
quotesAndAuthor(); // show a quote on load
27+
document.getElementById("new-quote").addEventListener("click", () => {
28+
quotesAndAuthor();
29+
});
30+
}
31+
window.onload = setup;
1732

1833
// You don't need to change this function
1934
function pickFromArray(choices) {

0 commit comments

Comments
 (0)