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
34 changes: 22 additions & 12 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<script defer src="quotes.js"></script>
</head>
<body>
<h1>hello there</h1>
<p id="quote"></p>

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Quote Generator</title>
<script defer src="quotes.js"></script>
<link rel="stylesheet" href="style.css">
</head>

<body>
<div class="quote-wrapper">
<h1 id="quote"></h1>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
</body>
</html>
<div class="controls">
<input type="checkbox" class="toggle" id="auto-play" />
<label for="auto-play" id="auto-play-status">auto-play:OFF</label>
<button type="button" id="new-quote">New quote</button>
</div>

</div>
</body>

</html>
35 changes: 35 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,38 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote

//dom elements
const body = document.querySelector("body");
const quoteText = document.getElementById("quote");
const authorText = document.getElementById("author");
const newQuote = document.getElementById("new-quote");
const autoPlay = document.getElementById("auto-play");
const autoPlayStatus = document.getElementById("auto-play-status");

//event listeners
body.addEventListener("load",getQuote());
newQuote.addEventListener("click", getQuote);
autoPlay.addEventListener("input", autoplay);

//functions

function getQuote() {
const randomIndex = Math.floor(Math.random() * quotes.length);
const quote = quotes[randomIndex]
quoteText.innerText = `"${quote.quote}"`;
authorText.innerText = `- ${quote.author}`;
}

let intervalId;

function autoplay() {
if (autoPlay.checked) {
autoPlayStatus.innerText = "auto-play:ON";
intervalId = setInterval(getQuote, 5000);
} else {
autoPlayStatus.innerText= "auto-play:OFF";
clearInterval(intervalId);
}
}

91 changes: 91 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,92 @@
/** Write your CSS in here **/
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
font-family:;
background-color:#f3a83b;
}

.quote-wrapper {
background: white;
color: #f3a83b;
padding: 20px;
margin: 50px auto;
border-radius: 8px;
max-width: 80%;
height: auto;
}

h1 {
font-size: 24px;
}

#author {
text-align: right;
margin-top: 10px;
}

button {
background-color:#f3a83b;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}

.controls {
display: flex;
width: 100%;
align-items: center;
justify-content: space-between;
}

.toggle {
display: none;
}

label {
display: inline-block;
width: 125px;
padding: 10px 12px;
text-align: center;
background-color: white;
color: #f3a83b;
border: 1px solid #f3a83b;
border-radius: 5px;
position: relative;
cursor: pointer;
margin-left: 10px;
transition: background-color 0.3s;
}

label::before {
content: "x";
color: white;
position: absolute;
top: 3px;
left: 3px;
width: 20px;
height: 20px;
margin-top: 6.5px;
background-color: #f3a83b;
border-radius: 50%;
transition: transform 0.3s;
}

.toggle:checked + label {
background-color: #f3a83b;
color: white;
}

.toggle:checked + label::before {
content: '✔';
color: #f3a83b;
transform: translateX(120px);
background-color: white;
}