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
20 changes: 14 additions & 6 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<title>Quote Generator</title>
<link rel="stylesheet" href="style.css" />
<script defer src="quotes.js"></script>
<script defer src="script.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>
<main class="container">
<h1>Quote Generator</h1>

<section class="quote-card" aria-live="polite">
<p id="quote" class="quote-text">Loading quote...</p>
<p id="author" class="quote-author"></p>
</section>

<button type="button" id="new-quote">New Quote</button>
</main>
</body>
</html>
</html>
42 changes: 42 additions & 0 deletions Sprint-3/quote-generator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Get references to the HTML elements that will display
// the quote, the author, and the button
const quoteElement = document.getElementById("quote");
const authorElement = document.getElementById("author");
const newQuoteButton = document.getElementById("new-quote");

// Store the currently displayed quote so that
// we do not show the exact same quote twice in a row
let currentQuote = null;

/**
* Returns a random quote object from the quotes array.
* If a quote is already being displayed, this function
* keeps picking again until it gets a different one.
*/
function getNewRandomQuote() {
let randomQuote = pickFromArray(quotes);

while (quotes.length > 1 && randomQuote === currentQuote) {
randomQuote = pickFromArray(quotes);
}

return randomQuote;
}

/**
* Displays a random quote and its author on the page.
*/
function displayRandomQuote() {
const selectedQuote = getNewRandomQuote();

quoteElement.textContent = `"${selectedQuote.quote}"`;
authorElement.textContent = `— ${selectedQuote.author}`;

currentQuote = selectedQuote;
}

// Show a random quote as soon as the page loads
displayRandomQuote();

// Show a different random quote whenever the button is clicked
newQuoteButton.addEventListener("click", displayRandomQuote);
73 changes: 72 additions & 1 deletion Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,72 @@
/** Write your CSS in here **/
/* Apply box-sizing to all elements so padding and borders
do not affect the final width and height unexpectedly */
* {
box-sizing: border-box;
}

/* Basic page styling */
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
background-color: #f4f4f4;
color: #222222;
}

/* Main layout container */
.container {
max-width: 750px;
margin: 60px auto;
padding: 20px;
text-align: center;
}

/* Page heading */
h1 {
margin-bottom: 30px;
font-size: 2rem;
}

/* Card that holds the quote and author */
.quote-card {
background-color: #ffffff;
border-radius: 12px;
padding: 30px 20px;
margin-bottom: 25px;
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

/* Quote text styling */
.quote-text {
font-size: 1.5rem;
line-height: 1.6;
margin-bottom: 20px;
}

/* Author text styling */
.quote-author {
font-size: 1.1rem;
font-weight: bold;
color: #555555;
}

/* Button styling */
#new-quote {
padding: 12px 24px;
font-size: 1rem;
border: none;
border-radius: 8px;
background-color: #0b5ed7;
color: #ffffff;
cursor: pointer;
}

/* Button hover state */
#new-quote:hover {
background-color: #094db1;
}

/* Button keyboard focus state */
#new-quote:focus {
outline: 3px solid #99c2ff;
outline-offset: 3px;
}/** Write your CSS in here **/
Loading