-
-
Notifications
You must be signed in to change notification settings - Fork 299
BIRMINGHAM | ITP-JAN 26 | Merve Reis | Sprint 3 | Quote Generator #1043
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,27 @@ | ||
| <!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> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Quote generator app</title> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| <script defer src="quotes.js"></script> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div class="card"> | ||
| <p id="quote"></p> | ||
| <p id="author"></p> | ||
| <button type="button" id="new-quote">New quote</button> | ||
| </body> | ||
| </html> | ||
|
|
||
| <div class="controls"> | ||
| <label class="toggle-label"> | ||
| <input type="checkbox" id="autoplay-toggle" /> | ||
| <span id="autoplay-status">Auto Play: OFF</span> | ||
| </label> | ||
| <button type="button" id="new-quote">New quote</button> | ||
| </div> | ||
| </div> | ||
| </body> | ||
|
|
||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -491,3 +491,32 @@ const quotes = [ | |
| ]; | ||
|
|
||
| // call pickFromArray with the quotes array to check you get a random quote | ||
| const quoteEl = document.getElementById("quote"); | ||
| const authorEl = document.getElementById("author"); | ||
| const btn = document.getElementById("new-quote"); | ||
| const toggle = document.getElementById("autoplay-toggle"); | ||
| const statusEl = document.getElementById("autoplay-status"); | ||
|
|
||
| let interval = null; | ||
|
|
||
| function showQuote() { | ||
| const picked = pickFromArray(quotes); | ||
| console.log(picked); | ||
| quoteEl.textContent = picked.quote; | ||
| authorEl.textContent = "- " + picked.author; | ||
| } | ||
|
|
||
| btn.addEventListener("click", showQuote); | ||
|
|
||
| toggle.addEventListener("change", () => { | ||
| if (toggle.checked) { | ||
| statusEl.textContent = "Auto Play: ON"; | ||
| interval = setInterval(showQuote, 3000); | ||
| } else { | ||
| statusEl.textContent = "Auto Play: OFF"; | ||
| clearInterval(interval); | ||
| interval = null; | ||
| } | ||
| }); | ||
|
|
||
| showQuote(); | ||
|
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. Placing all the "run on load" code in one place is a good practice. For examples, function setup() {
// code to be executed on page load
}
window.addEventListener('load', setup);or window.addEventListener('load', function() {
// code to be executed on page load
});
Author
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. @cjyuan I moved the logic what we run while page load into the setup function then I called it with eventListener as you suggest |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,107 @@ | ||
| /** Write your CSS in here **/ | ||
| * { | ||
| margin: 0; | ||
| padding: 0; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| body { | ||
| min-height: 100vh; | ||
| background-color: #f5a800; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| font-family: Georgia, serif; | ||
| } | ||
|
|
||
| .card { | ||
| background: #fff; | ||
| padding: 60px 50px 40px; | ||
| max-width: 780px; | ||
| width: 90%; | ||
| border-radius: 4px; | ||
| position: relative; | ||
| } | ||
|
|
||
| .card::before { | ||
| content: "\201C"; | ||
| font-size: 120px; | ||
| color: #f5a800; | ||
| line-height: 0.6; | ||
| position: absolute; | ||
| top: 40px; | ||
| left: 40px; | ||
| } | ||
|
|
||
| #quote { | ||
| font-size: 1.4rem; | ||
| color: #f5a800; | ||
| margin-bottom: 20px; | ||
| padding-left: 60px; | ||
| line-height: 1.6; | ||
| } | ||
|
|
||
| #author { | ||
| font-size: 1.1rem; | ||
| color: #f5a800; | ||
| text-align: right; | ||
| margin-bottom: 30px; | ||
| } | ||
|
|
||
| .controls { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: flex-end; | ||
| gap: 20px; | ||
| } | ||
|
|
||
| button#new-quote { | ||
| background-color: #f5a800; | ||
| color: #fff; | ||
| border: none; | ||
| padding: 14px 28px; | ||
| font-size: 1rem; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| button#new-quote:hover { | ||
| background-color: #d99200; | ||
| } | ||
|
|
||
| /* Toggle switch */ | ||
| .toggle-label { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 10px; | ||
| cursor: pointer; | ||
| font-size: 0.9rem; | ||
| color: #f5a800; | ||
| } | ||
|
|
||
| .slider { | ||
| width: 44px; | ||
| height: 24px; | ||
| background: #ccc; | ||
| border-radius: 999px; | ||
| position: relative; | ||
| transition: background 0.3s; | ||
| } | ||
|
|
||
| .slider::after { | ||
| content: ""; | ||
| position: absolute; | ||
| width: 18px; | ||
| height: 18px; | ||
| background: #fff; | ||
| border-radius: 50%; | ||
| top: 3px; | ||
| left: 3px; | ||
| transition: transform 0.3s; | ||
| } | ||
|
|
||
| .toggle-label input:checked + .slider { | ||
| background: #f5a800; | ||
| } | ||
|
|
||
| .toggle-label input:checked + .slider::after { | ||
| transform: translateX(20px); | ||
| } |
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.
Since
"- "is part of the presentation logic, it is better to keep it in the CSS or in HTML.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.
@cjyuan I moved the '-' part to CSS file