Skip to content
15 changes: 9 additions & 6 deletions Sprint-3/quote-generator/index.html
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You missed updating part of index.html according to an instruction in readme.md.

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.

Thanks for reviewing @cjyuan. Index.html updated as per readme, new commit made. Thanks

Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<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>
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
<div class="quote-box">
<h1></h1>
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
</div>
</body>
</html>
17 changes: 16 additions & 1 deletion Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@

// You don't need to change this function
function pickFromArray(choices) {
return choices[Math.floor(Math.random() * choices.length)];
return choices[Math.floor(Math.random() * choices.length)]; // Math.random() generates a random number between 0 (inclusive) and 1 (exclusive). Multiplying it by choices.length gives a random number between 0 and the length of the array. Math.floor() rounds it down to the nearest whole number, which is used as an index to pick an item from the array.
}
function setup() {
const button = document.getElementById("new-quote"); // Get the button element using its DOM ID
const quoteElement = document.getElementById("quote");
const authorElement = document.getElementById("author");

function renderRandomQuote() {
const selectedQuote = pickFromArray(quotes); // Call the pickFromArray function with the quotes array to get a random quote
quoteElement.innerText = selectedQuote.quote; // Display quote
authorElement.innerText = selectedQuote.author; // Display author
}

renderRandomQuote();
button.addEventListener("click", renderRandomQuote); // Add a click event listener to the button
}

// A list of quotes you can use in your app.
Expand Down Expand Up @@ -491,3 +505,4 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote
setup();
1 change: 0 additions & 1 deletion Sprint-3/quote-generator/style.css

This file was deleted.