Skip to content

Commit f2dd477

Browse files
committed
Add random quote generator
1 parent e1b3006 commit f2dd477

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

Sprint-3/quote-generator/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@
1313
"bugs": {
1414
"url": "https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
1515
},
16-
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme"
16+
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
17+
"devDependencies": {
18+
"@testing-library/jest-dom": "^6.9.1",
19+
"jest": "^30.3.0",
20+
"jest-environment-jsdom": "^30.3.0"
21+
}
1722
}

Sprint-3/quote-generator/quotes.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,21 @@ const quotes = [
491491
];
492492

493493
// call pickFromArray with the quotes array to check you get a random quote
494+
495+
const quoteElement = document.getElementById("quote");
496+
const authorElement = document.getElementById("author");
497+
498+
function displayQuote() {
499+
const randomQuote = pickFromArray(quotes);
500+
501+
quoteElement.textContent = randomQuote.quote;
502+
authorElement.textContent = randomQuote.author;
503+
}
504+
505+
// Show a quote when page loads
506+
displayQuote();
507+
508+
// Change quote when button is clicked
509+
document
510+
.getElementById("new-quote")
511+
.addEventListener("click", displayQuote);

Sprint-3/quote-generator/style.css

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,36 @@
11
/** Write your CSS in here **/
2+
body {
3+
font-family: Arial, sans-serif;
4+
text-align: center;
5+
margin-top: 50px;
6+
background-color: #f5f5f5;
7+
}
8+
9+
h1 {
10+
color: #333;
11+
}
12+
13+
#quote {
14+
font-size: 24px;
15+
margin: 20px;
16+
font-style: italic;
17+
}
18+
19+
#author {
20+
font-size: 18px;
21+
color: #666;
22+
}
23+
24+
button {
25+
padding: 10px 20px;
26+
font-size: 16px;
27+
cursor: pointer;
28+
border: none;
29+
background-color: #333;
30+
color: white;
31+
border-radius: 5px;
32+
}
33+
34+
button:hover {
35+
background-color: #555;
36+
}

0 commit comments

Comments
 (0)