Skip to content

London | 25-ITP-May | Halyna Kozlovska | Sprint 3 | Quote Generator #620

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 5 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
3 changes: 2 additions & 1 deletion Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<link rel="stylesheet" href="style.css" />
<title>Quote generator app</title>
<script defer src="quotes.js"></script>
</head>
<body>
Expand Down
68 changes: 68 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,71 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote
function createContainer() {
const h1 = document.querySelector("h1");
if (h1) {
h1.remove();
}

const container = document.createElement('div');
container.id = 'quote-container';
container.className = 'container';

container.innerHTML = document.body.innerHTML;

document.body.innerHTML = "";
document.body.appendChild(container);

const autoPlayWrapper = document.createElement("div");
autoPlayWrapper.id = "auto-play-wrapper";
autoPlayWrapper.innerHTML = `
<label for="auto-play" class="auto-play-label">
<input type="checkbox" id="auto-play" />
<span>Auto Play:</span>
<span id="auto-play-status">OFF</span>
</label>
`;
document.body.appendChild(autoPlayWrapper);
}

let autoPlayInterval = null;

function handleAutoPlayToggle() {
const checkbox = document.getElementById("auto-play");
const status = document.getElementById("auto-play-status");

checkbox.addEventListener("change", () => {
if (checkbox.checked) {
status.textContent = "ON";
autoPlayInterval = setInterval(setQuoteAndAuthor, 60000);
} else {
status.textContent = "OFF";
clearInterval(autoPlayInterval);
}
});
}

function setQuoteAndAuthor() {
const result = pickFromArray(quotes);
document.querySelector(
"#quote"
).innerHTML = `<span class="mark">&ldquo;</span> ${result.quote}`;
document.querySelector('#author').innerHTML = `- ${result.author}`;
}

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

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

function renderQuote() {
createContainer();
setQuoteAndAuthor();
handleButton();
handleAutoPlayToggle();
}

renderQuote();
67 changes: 67 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,68 @@
/** Write your CSS in here **/
:root {
--main-bg-color: #f1b847;
--bg-color: #f5f5f5;
--shadow: 0 0 5px rgba(0,0,0,0.2);
}
body {
background-color: var(--main-bg-color);
color: var(--bg-color);
margin: 0;
padding: 0;
}
button {
background-color: var(--main-bg-color);
color: white;
border: none;
padding: 10px 20px;
cursor: pointer;
}
button:hover {
filter: brightness(90%);
}

.container {
background-color: var(--bg-color);
color: var(--main-bg-color);
box-shadow: var(--shadow);
text-align: right;
margin: 80px auto;
padding: 30px 40px;
max-width: 600px;
min-height: 150px;
font-size: 1.2em;
}
#quote {
font-size: 2rem;
line-height: 1.3;
}
#author {
margin-bottom: 24px;
}
.mark {
font-family:'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
font-size: 5rem;
font-weight: bold;
display: inline-block;
transform: translateY(0.4em);
line-height: 1;
}
#auto-play-wrapper {
width: 130px;
position: fixed;
top: 20px;
right: 20px;
background-color: var(--bg-color);
color: var(--main-bg-color);
padding: 8px 12px;
box-shadow: var(--shadow);
font-size: 0.9rem;
}
#auto-play-wrapper input {
cursor: pointer;
}
.auto-play-label {
display: flex;
align-items: center;
gap: 6px;
}