Skip to content

Commit 20c518e

Browse files
committed
Completed quote generator app
1 parent cfd674c commit 20c518e

File tree

3 files changed

+116
-7
lines changed

3 files changed

+116
-7
lines changed
Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>Title here</title>
6+
<title>Quote generator app</title>
77
<script defer src="quotes.js"></script>
8+
<link rel="stylesheet" href="./style.css" />
9+
<link rel="preconnect" href="https://fonts.googleapis.com" />
10+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
11+
<link
12+
href="https://fonts.googleapis.com/css2?family=SN+Pro:ital,wght@0,200..900;1,200..900&display=swap"
13+
rel="stylesheet"
14+
/>
815
</head>
916
<body>
10-
<h1>hello there</h1>
11-
<p id="quote"></p>
12-
<p id="author"></p>
13-
<button type="button" id="new-quote">New quote</button>
17+
<h1>Welcome to Quote Generator App</h1>
18+
<div class="auto-play">
19+
<label for="auto-play">Turn on Auto play?</label>
20+
<input type="checkbox" id="auto-play" name="auto-play" />
21+
<p id="auto-play-txt">Auto-Play: OFF</p>
22+
</div>
23+
<div class="container">
24+
<div class="quote-row">
25+
<img
26+
src="https://static.thenounproject.com/png/796160-200.png"
27+
alt="Opening quote mark"
28+
/>
29+
<p id="quote"></p>
30+
</div>
31+
<div class="group">
32+
<p id="author"></p>
33+
<button type="button" id="new-quote">New quote</button>
34+
</div>
35+
</div>
1436
</body>
1537
</html>

Sprint-3/quote-generator/quotes.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,34 @@ const quotes = [
491491
];
492492

493493
// call pickFromArray with the quotes array to check you get a random quote
494+
const newQuote = document.querySelector("#new-quote");
495+
const quoteTxt = document.querySelector("#quote");
496+
const quoteAuthor = document.querySelector("#author");
497+
const autoPlay = document.querySelector("#auto-play");
498+
const autoPlayTxt = document.querySelector("#auto-play-txt");
499+
const autoPlayTime = 60000;
500+
let autoPlayInterval = null;
501+
newQuote.addEventListener("click", displayQuote);
502+
503+
initaliseSite();
504+
autoPlay.addEventListener("change", () => {
505+
if (autoPlay.checked) {
506+
console.log("ON");
507+
autoPlayTxt.textContent = `Auto-Play: ON, changing quote every ${autoPlayTime / 1000} seconds.`;
508+
autoPlayInterval = setInterval(displayQuote, autoPlayTime);
509+
} else {
510+
console.log("OFF");
511+
autoPlayTxt.textContent = "Auto-Play: OFF";
512+
clearInterval(autoPlayInterval);
513+
}
514+
});
515+
516+
function initaliseSite() {
517+
displayQuote();
518+
}
519+
520+
function displayQuote() {
521+
const quote = pickFromArray(quotes);
522+
quoteTxt.innerHTML = `${quote.quote}`;
523+
quoteAuthor.textContent = `- ${quote.author}`;
524+
}

Sprint-3/quote-generator/style.css

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,57 @@
1-
/** Write your CSS in here **/
1+
body {
2+
background-color: orange;
3+
font-family: "SN Pro";
4+
}
5+
6+
h1 {
7+
text-align: center;
8+
font-size: 50px;
9+
}
10+
11+
.container {
12+
width: 50%;
13+
margin: auto;
14+
background-color: white;
15+
padding: 50px;
16+
}
17+
18+
.container img {
19+
width: 50px;
20+
height: 50px;
21+
}
22+
23+
.container p {
24+
font-size: 20px;
25+
}
26+
27+
.quote-row {
28+
display: flex;
29+
gap: 10px;
30+
}
31+
32+
#quote {
33+
font-weight: bold;
34+
}
35+
36+
.container button {
37+
padding: 10px;
38+
font-size: 20px;
39+
color: white;
40+
font-weight: bold;
41+
background-color: orange;
42+
}
43+
44+
.group {
45+
display: flex;
46+
flex-direction: column;
47+
align-items: flex-end;
48+
}
49+
50+
.auto-play {
51+
display: flex;
52+
justify-content: center;
53+
align-items: center;
54+
gap: 10px;
55+
font-size: 20px;
56+
padding: 20px;
57+
}

0 commit comments

Comments
 (0)