Skip to content
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

WM4 | FATIMA_SAFANA | MODULE-DATA-GROUPS | WEEK3 | QUOTE-GENERATOR #271

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<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>
Expand Down
20 changes: 19 additions & 1 deletion Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
// Step 1: Get the required elements
const quote = document.querySelector("#quote");
const author = document.querySelector("#author");
const newQuoteButton = document.querySelector("#new-quote");

// Step 2: Function to display a random quote
function displayRandomQuote() {
const randomQuote = pickFromArray(quotes);
quote.innerText = randomQuote.quote;
author.innerText = randomQuote.author;
}

// Step 3: Event listeners
document.addEventListener("DOMContentLoaded", displayRandomQuote);
newQuoteButton.addEventListener("click", displayRandomQuote);



// DO NOT EDIT BELOW HERE

// pickFromArray is a function which will return one item, at
Expand All @@ -14,7 +32,7 @@
// Examples of use
// ---------------
// pickFromArray(['a','b','c','d']) // maybe returns 'c'

// You don't need to change this function
function pickFromArray(choices) {
return choices[Math.floor(Math.random() * choices.length)];
Expand Down