generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 195
Manchester| 25-ITP-Sep| Fithi Teklom| Sprint 3 | Quote Generator App #915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Fithi-Teklom
wants to merge
8
commits into
CodeYourFuture:main
Choose a base branch
from
Fithi-Teklom:quote-generator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
96233e8
added a title
Fithi-Teklom 5888597
linked the css file
Fithi-Teklom 45fcc99
added a jest file
Fithi-Teklom fa5feab
wrapped the function inside windows load
Fithi-Teklom 8fc17ce
added a space
Fithi-Teklom dfc616d
modified style css
Fithi-Teklom 212fe40
added a switch on and off button
Fithi-Teklom 13c8ab0
auto play is working
Fithi-Teklom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| module.exports = { | ||
| testEnvironment: "jsdom", | ||
| testMatch: ["quote.test.js"], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,57 @@ | |
|
|
||
| // You don't need to change this function | ||
| function pickFromArray(choices) { | ||
| return choices[Math.floor(Math.random() * choices.length)]; | ||
| // You already have pickFromArray() and quotes[] above this comment | ||
| return choices[Math.floor(Math.random() * choices.length)] | ||
| }; | ||
| window.addEventListener("load", () => { | ||
| const quoteEl = document.getElementById("quote"); | ||
| const authorEl = document.getElementById("author"); | ||
| const button = document.getElementById("new-quote"); | ||
|
|
||
| // Generate a random quote using Math.random (required for tests) | ||
| function getRandomQuote() { | ||
| const index = Math.floor(Math.random() * quotes.length); | ||
| return quotes[index]; | ||
| } | ||
|
|
||
| // Put the quote + author into the DOM | ||
| function displayRandomQuote() { | ||
| const q = getRandomQuote(); | ||
| quoteEl.textContent = q.quote; | ||
| authorEl.textContent = q.author; | ||
| } | ||
|
|
||
| // Show initial quote immediately | ||
| displayRandomQuote(); | ||
|
|
||
| // Button shows a new quote | ||
| button.addEventListener("click", displayRandomQuote); | ||
| let autoPlayInterval = null; | ||
|
|
||
| const toggle = document.getElementById("auto-play-toggle"); | ||
| const statusText = document.getElementById("auto-status"); | ||
|
|
||
| toggle.addEventListener("change", () => { | ||
| if (toggle.checked) { | ||
| statusText.textContent = "auto-play:ON"; | ||
|
|
||
| // Change every 5 seconds (easy for testing) | ||
| autoPlayInterval = setInterval(() => { | ||
| pickQuoteAndAuthor(); | ||
| }, 5000); | ||
|
|
||
| pickQuoteAndAuthor(); // Change immediately | ||
| } else { | ||
| statusText.textContent = "auto-play:OFF"; | ||
| clearInterval(autoPlayInterval); | ||
| } | ||
| }); | ||
|
Comment on lines
46
to
67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could consider wrapping all the code and variables needed to support auto-play inside a function as: function setupAutoPlay() {
// JavaScript support closure. So even after this function call returns, the
// inner function can still access these variables.
let autoPlayInterval = null;
const toggle = document.getElementById("auto-play-toggle");
const statusText = document.getElementById("auto-status");
toggle.addEventListener("change", () => {
...
});
}and then call the function in the onload event listener as window.addEventListener("load", () => {
button.addEventListener("click", displayRandomQuote);
// By placing the setup code in a separate function, it makes finding out "what operations are
// performed once on page load" easier.
setupAutoPlay();
displayRandomQuote();
}); |
||
|
|
||
|
|
||
| // return choices[Math.floor(Math.random() * choices.length)]; | ||
| }); | ||
|
|
||
| // A list of quotes you can use in your app. | ||
| // DO NOT modify this array, otherwise the tests may break! | ||
| const quotes = [ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,109 @@ | ||
| /** Write your CSS in here **/ | ||
|
|
||
| body { | ||
| font-family: Arial, sans-serif; | ||
| background: linear-gradient(135deg, #f089cc, #d6eaff); | ||
| margin: 0; | ||
| padding: 40px; | ||
| text-align: center; | ||
| } | ||
|
|
||
| /* Page title */ | ||
| h1 { | ||
| color: black ; | ||
| font-size: 2rem; | ||
| margin-bottom: 20px; | ||
| } | ||
|
|
||
| /* Quote styling */ | ||
| #quote { | ||
| font-size: 1.5rem; | ||
| font-weight: bold; | ||
| color: black ; | ||
| margin: 20px auto 10px; | ||
| max-width: 600px; | ||
| line-height: 1.5; | ||
| } | ||
|
|
||
| /* Author name */ | ||
| #author { | ||
| font-size: 1.2rem; | ||
| color: #555; | ||
| margin-bottom: 30px; | ||
| } | ||
|
|
||
| /* Button styling */ | ||
| #new-quote { | ||
| padding: 12px 30px; | ||
| font-size: 1rem; | ||
| background-color: #007bff; | ||
| color: white; | ||
| border: none; | ||
| border-radius: 8px; | ||
| cursor: pointer; | ||
| transition: 0.25s ease; | ||
| } | ||
|
|
||
| /* Hover effect */ | ||
| #new-quote:hover { | ||
| background-color: #005ec2; | ||
| transform: scale(1.05); | ||
| } | ||
|
|
||
|
|
||
| /* Toggle switch container */ | ||
| .switch { | ||
| position: relative; | ||
| display: inline-block; | ||
| width: 50px; | ||
| height: 26px; | ||
| margin-top: 20px; | ||
| } | ||
|
|
||
| /* Hide default checkbox */ | ||
| .switch input { | ||
| opacity: 0; | ||
| width: 0; | ||
| height: 0; | ||
| } | ||
|
|
||
| /* Slider background */ | ||
| .slider { | ||
| position: absolute; | ||
| cursor: pointer; | ||
| top: 0; | ||
| left: 0; | ||
| right: 0; | ||
| bottom: 0; | ||
| background-color: #ccc; | ||
| border-radius: 26px; | ||
| transition: 0.4s; | ||
| } | ||
|
|
||
| /* Slider circle */ | ||
| .slider:before { | ||
| position: absolute; | ||
| content: ""; | ||
| height: 20px; | ||
| width: 20px; | ||
| left: 3px; | ||
| bottom: 3px; | ||
| background-color: white; | ||
| border-radius: 50%; | ||
| transition: 0.4s; | ||
| } | ||
|
|
||
| /* ON state */ | ||
| input:checked + .slider { | ||
| background-color: #4a90e2; | ||
| } | ||
|
|
||
| input:checked + .slider:before { | ||
| transform: translateX(24px); | ||
| } | ||
|
|
||
| #auto-status { | ||
| margin-top: 10px; | ||
| color: #333; | ||
| font-weight: bold; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "devDependencies": { | ||
| "@testing-library/jest-dom": "^6.9.1", | ||
| "@testing-library/user-event": "^13.5.0", | ||
| "jest": "^30.2.0", | ||
| "jsdom": "^19.0.0" | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could consider declaring top-level variables and defining functions outside of the onload event listener. Doing so could make finding out "what operations are performed once on page load" easier.