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
19 changes: 13 additions & 6 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
<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>
</head>
<body>
<h1>hello there</h1>
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
<body class="page">
<main class="quote-app">
<section class="quote-card">
<h1 class="quote-title">Daily quote</h1>
<p id="quote" class="quote-text"></p>
<p id="author" class="quote-author"></p>
<button type="button" id="new-quote" class="quote-button">
New quote
</button>
</section>
</main>
</body>
</html>
28 changes: 28 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,34 @@ function pickFromArray(choices) {
return choices[Math.floor(Math.random() * choices.length)];
}

function displayQuote() {
const quoteElement = document.getElementById("quote");
const authorElement = document.getElementById("author");
const randomItem = pickFromArray(quotes);

if (!quoteElement || !authorElement) {
return;
}

quoteElement.innerText = randomItem.quote;
authorElement.innerText = `— ${randomItem.author}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could consider keeping the - part (the static part) in HTML or CSS -- to more clearly separate the presentation logic from JS code.

}

function setupQuoteGenerator() {
const button = document.getElementById("new-quote");

if (button) {
button.addEventListener("click", () => {
displayQuote();
});
}

// Show one quote when the page opens
displayQuote();
}

window.addEventListener("DOMContentLoaded", setupQuoteGenerator);

// A list of quotes you can use in your app.
// DO NOT modify this array, otherwise the tests may break!
const quotes = [
Expand Down
80 changes: 79 additions & 1 deletion Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,79 @@
/** Write your CSS in here **/
.page {
font-family: "Georgia", "Times New Roman", serif;
background-color: #efa73d;
margin: 0;
min-height: 100vh;
}

/* Keep the main area simple and centered */
.quote-app {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}

.quote-card {
max-width: 900px;
width: 100%;
background-color: #ffffff;
border-radius: 10px;
padding: 40px 60px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
display: flex;
flex-direction: column;
gap: 20px;
}

.quote-title {
text-align: center;
margin-bottom: 18px;
color: #2b2d42;
font-size: 24px;
}

.quote-text {
font-size: 32px;
line-height: 1.5;
color: #d9812a;
margin: 0;
position: relative;
}

.quote-text::before {
content: "❝";
font-size: 56px;
color: #d9812a;
margin-right: 10px;
vertical-align: middle;
display: inline-block;
}

.quote-author {
text-align: right;
font-size: 20px;
color: #d9812a;
margin: 0;
}

.quote-button {
align-self: flex-end;
min-width: 140px;
padding: 12px;
font-size: 18px;
border: none;
border-radius: 8px;
background-color: #e7891b;
color: #ffffff;
cursor: pointer;
}

.quote-button:hover {
background-color: #cc6c07;
}

.quote-button:focus {
outline: 2px solid #9b4a00;
outline-offset: 2px;
}