Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
8 changes: 7 additions & 1 deletion Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<link rel="stylesheet" href="style.css">
<script defer src="quotes.js"></script>
</head>
<body>
<h1>hello there</h1>
<section>
<div class = "quote">
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
</div>
</section>
</body>
</html>


19 changes: 18 additions & 1 deletion Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,22 @@ const quotes = [
author: "Zig Ziglar",
},
];

const title = document.querySelector("title")
title.textContent = "Quote generator app";
Comment thread
cjyuan marked this conversation as resolved.
Outdated
// call pickFromArray with the quotes array to check you get a random quote
const quoteEl = document.querySelector("#quote");
const authorEl = document.querySelector("#author");
const button = document.querySelector("#new-quote");

function displayQuote() {
const randomQuote = pickFromArray(quotes);

quoteEl.textContent = randomQuote.quote;
authorEl.textContent = randomQuote.author;
}

// Show initial quote on page load
displayQuote();

// Change quote when button is clicked
button.addEventListener("click", displayQuote);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.
Would be even better to place the code
inside a function to make it clearer that "this is what runs when the page loads."

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

thanks for the feed, onl page load function added

23 changes: 23 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
/** Write your CSS in here **/
*{
box-sizing: border-box;
}
body{
background-color: orange;
}
.quote{
background-color: white;
text-align: center;
padding: 50px;
margin: 50px;
color: orange;
font-size: larger;

}
button{
position: absolute;
right: 120px;
background-color: orange;
color: white;
border: orange;
padding: 8px;
}
Loading