Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<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>
<h1>hello there</h1>
<h1>Quote Generator</h1>
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
Expand Down
2 changes: 1 addition & 1 deletion Sprint-3/quote-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"url": "https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
},
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme"
}
}
17 changes: 17 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,20 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote
function getRandomQuote() {
return pickFromArray(quotes);
}
Comment on lines +494 to +496

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would like to know more about your design and thinking process. Just wondering why you would prefer implement this with a separate function? Thank you.

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.

Hi, yes that is a bit strange that I did that... Maybe I didn't like the name pickFromArray and wanted to call a function called getRandomQuote instead without modifying pickFromArray. And maybe I wanted to call getRandomQuote without sending in the huge array as a parameter. But in practice it does the same thing. Would you like me to remove it before you mark as complete?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It's alright and I understand more about your thought. Thank you.


function displayQuote() {
const quoteEl = document.querySelector("#quote");
const authorEl = document.querySelector("#author");
const quoteObj = getRandomQuote();
quoteEl.innerText = quoteObj.quote;
authorEl.innerText = quoteObj.author;
}

displayQuote();

const buttonEl = document.querySelector("#new-quote");

buttonEl.addEventListener("click", displayQuote);
Loading