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
10 changes: 8 additions & 2 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
<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>Random Quote Generator</h1>
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
</body>
</html>

<head>
<!-- ... -->
<link rel="stylesheet" href="style.css">
<script defer src="quotes.js"></script>
</head>
5 changes: 4 additions & 1 deletion Sprint-3/quote-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"bugs": {
"url": "https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
},
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme"
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
"dependencies": {
"@testing-library/user-event": "^13.5.0"
}
}
31 changes: 30 additions & 1 deletion Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,33 @@ const quotes = [
},
];

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

// 1. func: get random quote
function getRandomQuote() {
// random index from 0 to (quotes.length -1)
const randomIndex = Math.floor(Math.random() * quotes.length);

// return quotes object
return quotes[randomIndex]
}

// 2. func: display object on page
function displayQuote(quoteObject) {
// find DOM elements
const quoteElement = document.getElementById("quote");
const authorElement = document.getElementById("author");

// reload text
quoteElement.textContent = quoteObject.quote;
authorElement.textContent = quoteObject.author;
}

// 3. page load -> show random quote
displayQuote(getRandomQuote());

// 4. reload button -> show new quote
const button = document.getElementById("new-quote");
button.addEventListener("click", () => {
displayQuote(getRandomQuote());
});
58 changes: 58 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
/** Write your CSS in here **/
body {
font-family: 'Georgia', serif;
max-width: 600px;
margin: 50px auto;
padding: 20px;
text-align: center;
background-color: #f5f5f5;
}

h1 {
color: #333;
margin-bottom: 30px;
}

#quote {
font-size: 24px;
font-style: italic;
color: #555;
margin: 20px 0;
line-height: 1.6;
}

#quote::before {
content: '"';
font-size: 48px;
color: #ddd;
}

#quote::after {
content: '"';
font-size: 48px;
color: #ddd;
}

#author {
font-size: 18px;
color: #777;
margin-bottom: 30px;
}

#author::before {
content: '— ';
}

button {
background-color: #4CAF50;
color: white;
padding: 12px 30px;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}

button:hover {
background-color: #45a049;
}
1 change: 1 addition & 0 deletions Sprint-3/reading-list/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
<script src="script.js"></script>
</body>
</html>