Skip to content

Sheffield | ITP-May-2025 | Waleed-Yahya Salih-Taha | Sprint-3 | Quote-generator #731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
37 changes: 25 additions & 12 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<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>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Quote Generator App</title>

<!-- Optional: Link to CSS if styling is needed -->
<link rel="stylesheet" href="style.css" />

<!-- Load JavaScript after DOM is ready -->
<script defer src="quotes.js"></script>
</head>
<body class="center">
<main>
<h1>Quote Generator</h1>

<section id="quote-box" aria-live="polite">
<p id="quote"></p>
<p id="author"></p>
</section>

<button type="button" id="new-quote">
New Quote
</button>
</main>
</body>
</html>
21 changes: 21 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,24 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote
function getRandomQuote() {
const index = Math.floor(Math.random() * quotes.length);
return quotes[index];
}
function displayQuote(quoteObj) {
const quoteElement = document.getElementById("quote");
const authorElement = document.getElementById("author");

quoteElement.innerText = quoteObj.quote;
authorElement.innerText = quoteObj.author;
}
window.addEventListener("DOMContentLoaded", () => {
const newQuoteBtn = document.getElementById("new-quote");

// Show initial quote
displayQuote(getRandomQuote());
// Show a new quote when the button is clicked
newQuoteBtn.addEventListener("click", () => {
displayQuote(getRandomQuote());
});
});
68 changes: 68 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,69 @@
/** Write your CSS in here **/
* {
margin: 2px;
padding: 2px;
box-sizing: border-box;
}

body.centre {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(to right, #1644da, #e2e2e2);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 2rem;
}

/* Heading */
h1 {
margin-bottom: 2rem;
color: #2c3e50;
}

/* Quote Box */
#quote-box {
background: linear-gradient(135deg, #2980b9, #6dd5fa);
color: white;
border-radius: 15px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
padding: 2rem 3rem;
max-width: 600px;
width: 90%;
text-align: center;
margin-bottom: 2rem;
}

/* Quote Text */
#quote {
font-size: 1.5rem;
font-weight: 600;
margin-bottom: 1rem;
text-align: center;
}

/* Author Text */
#author {
font-size: 1.1rem;
font-style: italic;
}

/* Button */
#new-quote {
background-color: #ffffff;
color: #2980b9;
border: none;
padding: 0.75rem 1.5rem;
font-size: 1rem;
font-weight: bold;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

#new-quote:hover {
background-color: #2abfe4;
transform: translateY(-2px);
}