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
18 changes: 13 additions & 5 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
<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>
<script defer src="quotes.js"></script>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h1>hello there</h1>
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
<div id="slide-bar">
<label class="switch">
<input id="toggle-btn" type="checkbox" />
<span class="slider round"></span>
</label>
</div>
<div id="poster">
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
</div>
</body>
</html>
28 changes: 28 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,31 @@ const quotes = [
];

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

function updateQuoteAndAuthor() {
const { quote, author } = pickFromArray(quotes);
document.getElementById("quote").innerText = quote;
document.getElementById("author").innerText = author;
}

function autoUpdateQuoteAndAuthor() {
let autoQuote = document.getElementById("toggle-btn");
let intervalId;
autoQuote.addEventListener("change", () => {
if (autoQuote.checked) {
intervalId = setInterval(() => {
updateQuoteAndAuthor();
}, 3000);
} else {
clearInterval(intervalId);
}
});
}

window.onload = () => {
updateQuoteAndAuthor();
autoUpdateQuoteAndAuthor();
document
.getElementById("new-quote")
.addEventListener("click", updateQuoteAndAuthor);
Copy link

Choose a reason for hiding this comment

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

You have implemented the first part of this task quite well. However, you have yet to attempt the "auto-generate" task. Why is that?

Copy link
Author

Choose a reason for hiding this comment

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

I was concerned that I couldn't figure out why the second test keeps failing. So, I made this pull request to seek for guidelines. However, if it is ok to move on, I would love to try implementing new features.

Copy link
Author

Choose a reason for hiding this comment

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

Hi sambabib,
I have added an auto-update feature for the quote generator.

};
100 changes: 100 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,101 @@
/** Write your CSS in here **/
:root {
--primary-bg-color: #e9b066;
--primary-color: #ffffff;
--auto-activated: #8fc9f8;
}

body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
background-color: var(--primary-bg-color);
}

#poster {
width: 80%;
padding: 25px;
background-color: var(--primary-color);
color: var(--primary-bg-color);
font-size: larger;
font-style: italic;
position: relative;
top: 150px;
}

#quote {
font-weight: bold;
}

#slide-bar {
display: flex;
justify-content: end;
width: 90%;
}

button {
border-radius: 8px;
font-size: medium;
background-color: var(--primary-bg-color);
color: var(--primary-color);
border: none;
}

.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}

.switch input {
opacity: 0;
width: 0;
height: 0;
}

/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: var(--primary-color);
transition: 0.4s;
}

.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: var(--primary-bg-color);
transition: 0.4s;
}

input:checked + .slider {
background-color: var(--auto-activated);
}

input:focus + .slider {
box-shadow: 0 0 1px var(--auto-activated);
}

input:checked + .slider:before {
transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
border-radius: 34px;
}

.slider.round:before {
border-radius: 50%;
}
Loading