Skip to content
Closed
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
29 changes: 16 additions & 13 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<!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>
<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>
</body>
</html>

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Quote generator app</title>
<script defer src="quotes.js"></script>
</head>

<body>
<h1>Quote generator</h1>
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
</body>

</html>
7 changes: 7 additions & 0 deletions Sprint-3/quote-generator/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// jest.setup.js

const { TextDecoder, TextEncoder } = require("node:util");
require("@testing-library/jest-dom");

global.TextDecoder = TextDecoder;
global.TextEncoder = TextEncoder;
18 changes: 18 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,21 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote

// Grab elements
const quoteEl = document.getElementById("quote");
const authorEl = document.getElementById("author");
const newQuoteBtn = document.getElementById("new-quote");

// Function to show a random quote
function showRandomQuote() {
const randomQuote = pickFromArray(quotes);
quoteEl.innerText = randomQuote.quote;
authorEl.innerText = randomQuote.author;
}

// Show a random quote when the page loads
window.addEventListener("load", showRandomQuote);

// Change quote when button clicked
newQuoteBtn.addEventListener("click", showRandomQuote);
Loading