Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 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
23 changes: 18 additions & 5 deletions Sprint-3/quote-generator/index.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
<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>
Comment on lines 12 to 15
Copy link

Choose a reason for hiding this comment

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

Would the screen reader be able to understand what this button is for from the context?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you, Bhuwan. I should have added an aria-label for the input.

</div>
<div id="poster">
<p id="quote"></p>
<p id="author"></p>
<div id="button-field">
<button type="button" id="new-quote">New quote</button>
</div>
<div id="display-notice">
<p id="auto-play-notice" style="display: none">Auto-Play: On</p>
</div>
</div>
</body>
</html>
Empty file modified Sprint-3/quote-generator/package.json
100644 → 100755
Empty file.
Empty file modified Sprint-3/quote-generator/quote_generator_example.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Sprint-3/quote-generator/quotes.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,37 @@ 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").textContent = quote;
document.getElementById("author").textContent = author;
}

function autoUpdateQuoteAndAuthor() {
const autoQuote = document.getElementById("toggle-btn");
const newQuoteButton = document.getElementById("new-quote");
const autoDisplayNotice = document.getElementById("auto-play-notice");
let intervalId;
autoQuote.addEventListener("change", () => {
if (autoQuote.checked) {
newQuoteButton.style.display = "none";
autoDisplayNotice.style.display = "block";
intervalId = setInterval(() => {
updateQuoteAndAuthor();
}, 3000);
Copy link

Choose a reason for hiding this comment

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

In the readme for this task, the submission it mentions that auto quote should have 60 seconds interval when changing. Does this auto change in 60 secs, how would you fix that. Also this 3000 in your code are known as magic numbers, is there better way to handle magic numbers

Copy link
Author

Choose a reason for hiding this comment

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

Yes. I have added two variables for a preferred second and MS, which could improve readability.

} else {
clearInterval(intervalId);
newQuoteButton.style.display = "block";
autoDisplayNotice.style.display = "none";
}
});
}

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.

};
Empty file modified Sprint-3/quote-generator/quotes.test.js
100644 → 100755
Empty file.
Empty file modified Sprint-3/quote-generator/readme.md
100644 → 100755
Empty file.
115 changes: 115 additions & 0 deletions Sprint-3/quote-generator/style.css
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,116 @@
/** 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-field {
display: flex;
justify-content: end;
margin-bottom: -10px;
}

#display-notice {
display: flex;
justify-content: end;
}

#auto-display-notice {
font-size: 12px;
}

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%;
}