Skip to content

Commit 90e5f08

Browse files
author
Enice-Codes
committed
added css,js and html code to complete project,quotes.test.js
1 parent de6889c commit 90e5f08

3 files changed

Lines changed: 216 additions & 6 deletions

File tree

‎Sprint-3/quote-generator/index.html‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@
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>
7+
<link rel="stylesheet" href="styles.css" />
78
<script defer src="quotes.js"></script>
89
</head>
910
<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>
11+
<main class="card">
12+
<h1 class="visually-hidden">Quote generator app</h1>
13+
14+
<div class="quote-container">
15+
<p id="quote"></p>
16+
</div>
17+
18+
<div class="author-container">
19+
<p id="author"></p>
20+
</div>
21+
22+
<div class="controls">
23+
<button type="button" id="new-quote">New quote</button>
24+
</div>
25+
26+
<label class="autoplay-toggle">
27+
<input type="checkbox" id="autoplay-checkbox" />
28+
Auto-play
29+
</label>
30+
<p id="autoplay-status"></p>
31+
</main>
1432
</body>
15-
</html>
33+
</html>

‎Sprint-3/quote-generator/quotes.js‎

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

493493
// call pickFromArray with the quotes array to check you get a random quote
494+
function pickFromArray(array) {
495+
const randomIndex = Math.floor(Math.random() * array.length);
496+
return array[randomIndex];
497+
}
498+
499+
// Grab the elements we need to update once, so we're not
500+
// searching the page every time.
501+
const quoteEl = document.getElementById("quote");
502+
const authorEl = document.getElementById("author");
503+
const newQuoteButton = document.getElementById("new-quote");
504+
const autoplayCheckbox = document.getElementById("autoplay-checkbox");
505+
const autoplayStatusEl = document.getElementById("autoplay-status");
506+
507+
// This will hold the id returned by setInterval so we can
508+
// stop it again later when auto-play is switched off.
509+
let autoplayIntervalId = null;
510+
511+
// How often to change the quote automatically, in milliseconds.
512+
// Set to 60 seconds as per the brief - turn this down to
513+
// something like 5000 (5 seconds) while you're testing.
514+
const AUTOPLAY_INTERVAL_MS = 60000;
515+
516+
// Picks a new random quote and displays it on the screen.
517+
function showRandomQuote() {
518+
const randomQuote = pickFromArray(quotes);
519+
// If you prefer the Math.random() approach directly, you could
520+
// instead write:
521+
// const randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
522+
523+
quoteEl.textContent = `"${randomQuote.quote}"`;
524+
authorEl.textContent = `— ${randomQuote.author}`;
525+
}
526+
527+
// Updates the on-screen text that says whether auto-play is on or off.
528+
function updateAutoplayStatus(isOn) {
529+
autoplayStatusEl.textContent = isOn
530+
? "auto-play: ON — a new quote will appear every 60 seconds."
531+
: "auto-play: OFF — quotes will only change when you click the button.";
532+
}
533+
534+
// Turns auto-play on: shows a new quote immediately, then keeps
535+
// showing a new one every AUTOPLAY_INTERVAL_MS.
536+
function startAutoplay() {
537+
updateAutoplayStatus(true);
538+
autoplayIntervalId = setInterval(showRandomQuote, AUTOPLAY_INTERVAL_MS);
539+
}
540+
541+
// Turns auto-play off: stops the repeating timer so the quote
542+
// stops changing by itself.
543+
function stopAutoplay() {
544+
updateAutoplayStatus(false);
545+
clearInterval(autoplayIntervalId);
546+
autoplayIntervalId = null;
547+
}
548+
549+
// Wire everything up once the page has loaded.
550+
document.addEventListener("DOMContentLoaded", () => {
551+
// Show a random quote as soon as the page loads.
552+
showRandomQuote();
553+
554+
// Show a new quote whenever the button is clicked.
555+
newQuoteButton.addEventListener("click", showRandomQuote);
556+
557+
// Start in the "off" state so the status text is correct
558+
// even before the user touches the checkbox.
559+
updateAutoplayStatus(false);
560+
561+
// Toggle auto-play on/off when the checkbox is switched.
562+
autoplayCheckbox.addEventListener("change", () => {
563+
if (autoplayCheckbox.checked) {
564+
startAutoplay();
565+
} else {
566+
stopAutoplay();
567+
}
568+
});
569+
});

‎Sprint-3/quote-generator/style.css‎

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,117 @@
11
/** Write your CSS in here **/
2+
:root {
3+
--accent: #ff9f0a;
4+
--accent-dark: #e08600;
5+
}
6+
7+
* {
8+
box-sizing: border-box;
9+
}
10+
11+
body {
12+
font-family: Georgia, "Times New Roman", serif;
13+
background: var(--accent);
14+
display: flex;
15+
justify-content: center;
16+
align-items: center;
17+
min-height: 100vh;
18+
margin: 0;
19+
padding: 2rem;
20+
}
21+
22+
.visually-hidden {
23+
position: absolute;
24+
width: 1px;
25+
height: 1px;
26+
padding: 0;
27+
margin: -1px;
28+
overflow: hidden;
29+
clip: rect(0, 0, 0, 0);
30+
white-space: nowrap;
31+
border: 0;
32+
}
33+
34+
.card {
35+
background: #fff;
36+
padding: 3rem 3.5rem;
37+
max-width: 700px;
38+
width: 100%;
39+
}
40+
41+
.quote-container {
42+
position: relative;
43+
padding-left: 3rem;
44+
margin-bottom: 1.5rem;
45+
}
46+
47+
.quote-container::before {
48+
content: "\201C";
49+
position: absolute;
50+
left: 0;
51+
top: -0.6rem;
52+
font-size: 4rem;
53+
line-height: 1;
54+
font-weight: bold;
55+
color: var(--accent);
56+
}
57+
58+
#quote {
59+
font-size: 1.6rem;
60+
color: var(--accent);
61+
margin: 0;
62+
line-height: 1.4;
63+
}
64+
65+
.author-container {
66+
text-align: right;
67+
margin-bottom: 2rem;
68+
}
69+
70+
#author {
71+
font-size: 1.1rem;
72+
color: var(--accent);
73+
margin: 0;
74+
}
75+
76+
#author::before {
77+
content: "- ";
78+
}
79+
80+
.controls {
81+
display: flex;
82+
justify-content: flex-end;
83+
}
84+
85+
button {
86+
font-family: system-ui, sans-serif;
87+
padding: 0.85rem 1.75rem;
88+
border: none;
89+
background: var(--accent);
90+
color: #fff;
91+
font-size: 1rem;
92+
font-weight: 600;
93+
cursor: pointer;
94+
}
95+
96+
button:hover {
97+
background: var(--accent-dark);
98+
}
99+
100+
.autoplay-toggle {
101+
display: flex;
102+
align-items: center;
103+
justify-content: flex-end;
104+
gap: 0.4rem;
105+
font-family: system-ui, sans-serif;
106+
font-size: 0.9rem;
107+
color: #888;
108+
margin-top: 1rem;
109+
}
110+
111+
#autoplay-status {
112+
font-family: system-ui, sans-serif;
113+
font-size: 0.8rem;
114+
color: #999;
115+
text-align: right;
116+
margin: 0.25rem 0 0;
117+
}

0 commit comments

Comments
 (0)