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
4 changes: 3 additions & 1 deletion Sprint-3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
"devDependencies": {
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/user-event": "^14.6.1",
"jest": "^30.0.4",
"jest-environment-jsdom": "^30.0.4"
},
"dependencies": {
"@testing-library/user-event": "^13.5.0"
}
}
13 changes: 8 additions & 5 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
<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>
<link rel="stylesheet" href="./style.css" />
</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-container">
<h1>Quote Generator</h1>
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
</div>
</body>
</html>
21 changes: 20 additions & 1 deletion Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,23 @@ const quotes = [
},
];

// call pickFromArray with the quotes array to check you get a random quote
// Function to display a random quote on the page
function displayRandomQuote() {

Choose a reason for hiding this comment

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

Good job keeping displayRandomQuote() focused on a single responsibility — fetching a quote and updating the DOM. This helps keep the logic readable and easy to maintain.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you so much, @jaymes15.

// Pick a random quote object from the quotes array
const randomQuote = pickFromArray(quotes);

// Update the quote text on the page
document.getElementById("quote").textContent = randomQuote.quote;

// Update the author name on the page
document.getElementById("author").textContent = randomQuote.author;
}

// Add a click event listener to the "New quote" button
document.getElementById("new-quote").addEventListener("click", () => {

Choose a reason for hiding this comment

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

This is good! but we can make it cleaner by using a named function.
for example:
document.getElementById("new-quote").addEventListener("click", displayRandomQuote);

// When the button is clicked, display a new random quote
displayRandomQuote();
});

// show a random quote when page loads
displayRandomQuote();
57 changes: 57 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,58 @@
/** Write your CSS in here **/
/* Reset some default styles */
body {
font-family: "Helvetica", "Arial", sans-serif;
background-color: #ec8a09;
color: #333;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
padding: 20px;
text-align: center;
}

.quote-container {
display: flex;
flex-direction: column; /* stack quote, author, button vertically */
align-items: center; /* center quote and author horizontally */
background-color: #f7f3ee;
padding: 30px 40px;
border-radius: 15px;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
max-width: 600px;
width: 100%;
}

#quote {
font-size: 1.5rem;
font-style: italic;
margin-bottom: 15px;
color: #f86510;
}

#author {
font-size: 1.2rem;
font-weight: bold;
color: #f86510;
margin-bottom: 20px;
align-self: flex-end; /* moves author to the right */
}

#new-quote {
align-self: flex-end; /* pushes button to the right edge of container */
margin-top: 20px; /* optional spacing from the quote */
background-color: #4caf50;
color: white;
border: none;
padding: 12px 25px;
border-radius: 8px;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.3s ease;
}

#new-quote:hover {
background-color: #45a049;
}