Skip to content

NW | ITP-May-25 | Geraldine Edwards | Module-Data-Groups | Sprint-3 | Quote Generator App #586

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 1 commit 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
15 changes: 10 additions & 5 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
<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>
<link rel="stylesheet" href="styles.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>
<h1>Quote Generator</h1>
<div id="quote-container">
<div id="quote-box">
<p id="quote"></p>
<p id="author"></p>
</div>
<button type="button" id="new-quote">New quote</button>
</div>
</body>
</html>
27 changes: 27 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
//test expects this initial quote to be displayed
window.addEventListener("load", () => {
const initialQuote = {
quote: "Strive not to be a success, but rather to be of value.",
author: "Albert Einstein",
};

//display the initial quote and author on page load
document.querySelector("#quote").innerText = initialQuote.quote;
document.querySelector("#author").innerText = initialQuote.author;
});

function displayRandomQuote() {
//pick a random quote from the quotes array
const randomQuote = pickFromArray(quotes);

//display the random quote and author in the HTML elements
document.querySelector("#quote").innerText = randomQuote.quote;
document.querySelector("#author").innerText = randomQuote.author;
Comment on lines +18 to +19
Copy link
Member

Choose a reason for hiding this comment

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

This "set both elements to show the quote details" behaviour is repeated twice in your app - if we needed to change it in the future, we'd need to change both locations. Can you think of a way to avoid this?

}

//add an event listener to the button to generate a new random quote
document
.querySelector("#new-quote")
.addEventListener("click", displayRandomQuote);

// DO NOT EDIT BELOW HERE

// pickFromArray is a function which will return one item, at
Expand Down Expand Up @@ -491,3 +517,4 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote
const randomQuote = pickFromArray(quotes);
Copy link
Member

Choose a reason for hiding this comment

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

What does this variable do, and how is it used? What would break if you removed it?

88 changes: 88 additions & 0 deletions Sprint-3/quote-generator/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
:root {
--font-family: "Helvetica Neue", Arial, sans-serif;
--font-size: 1.5rem;
--primary-colour: darkolivegreen;
--secondary-colour: linen;
--text-colour: rgb(41, 58, 11);
--padding: 20px;
--border-radius: 10px;
--box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

h1 {
font-family: var(--font-family);
font-size: 2.5rem;
color: var(--text-colour);
text-align: center;
margin-bottom: 30px;
font-weight: bold;
letter-spacing: 1px;
}
body {
font-family: var(--font-family);
background-color: var(--secondary-colour);
margin: 0;
padding: 40px 20px;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
}
button {
background-color: var(--secondary-colour);
color: var(--text-colour);
font-family: var(--font-family);
font-size: 1.2rem;
padding: var(--padding);
margin-top: 30px;
border: none;
border-radius: var(--border-radius);
box-shadow: var(--box-shadow);
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}

/* Add click down effect */
button:active {
transform: translateY(2px);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#quote-container {
background-color: var(--primary-colour);
width: 600px;
height: 400px;
padding: var(--padding);
border-radius: var(--border-radius);
box-shadow: var(--box-shadow);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

#quote-box {
background-color: var(--secondary-colour);
padding: var(--padding);
color: var(--text-colour);
border-radius: var(--border-radius);
box-shadow: var(--box-shadow);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

#quote {
font-size: var(--font-size);
text-align: center;
}
#author {
font-size: 1rem;
font-style: italic;
font-weight: bold;
}