Skip to content
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
24 changes: 18 additions & 6 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,25 @@
<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="style.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>
</body>
<div class="wrapper">
<div class="quote-box">
<p id="quote" class="quote-text"></p>
<p id="author" class="quote-author"></p>
<button type="button" id="new-quote" class="quote-btn">New quote</button>

<div class="autoplay-wrapper">
<label>
<input type="checkbox" id="autoplay-toggle" />
Auto-play
</label>
<span id="autoplay-status">Auto-play: OFF</span>
</div>
</div>
</div>
</body>
</html>
30 changes: 30 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,34 @@ const quotes = [
},
];

function showRandomQuote() {
const random = pickFromArray(quotes);
document.getElementById("quote").textContent = random.quote;
document.getElementById("author").textContent = `– ${random.author}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could consider specifying the - part (a piece of static content) in HTML or in CSS.

}

document.addEventListener("DOMContentLoaded", showRandomQuote);

document.getElementById("new-quote").addEventListener("click", showRandomQuote);

let intervalId = null;
const toggle = document.getElementById("autoplay-toggle");
const statusText = document.getElementById("autoplay-status");

// Change every 5 seconds (60 seconds for final version)
const INTERVAL_TIME = 5000;

toggle.addEventListener("change", function () {
if (this.checked) {
// Turn ON auto-play
statusText.textContent = "Auto-play: ON";
intervalId = setInterval(showRandomQuote, INTERVAL_TIME);
} else {
// Turn OFF auto-play
statusText.textContent = "Auto-play: OFF";
clearInterval(intervalId);
intervalId = null;
}
});

// call pickFromArray with the quotes array to check you get a random quote
62 changes: 62 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,63 @@
/** Write your CSS in here **/

body {
margin: 0;
padding: 0;
background-color: #abeee4;
font-family: Arial, Helvetica, sans-serif;
}

.wrapper {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}

.quote-box {
background-color: white;
width: 70%;
max-width: 900px;
padding: 50px 60px;
border-radius: 4px;
color: #d88d24;
box-shadow: 0px 3px 10px rgba(0, 0, 0, 0.1);
}

.quote-text {
font-size: 30px;
font-weight: 600;
line-height: 1.4;
margin-bottom: 30px;
}

.quote-author {
text-align: right;
font-size: 20px;
margin-bottom: 40px;
}

.quote-btn {
background-color: #8ca5ca;
color: white;
padding: 12px 25px;
border: none;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
}

.autoplay-wrapper {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 20px;
font-size: 16px;
}

#autoplay-status {
font-weight: bold;
color: #d88d24;
}