Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 8 additions & 5 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
<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>
<link rel="stylesheet" href="style.css" />
<script defer src="quotes.js"></script>
</head>
<body>
<h1>hello there</h1>
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
<h1 class="greeting">Hello There, Enjoy the Quote</h1>
<div class="quote-box">
<blockquote id="quote"></blockquote>
<p class="author" id="author"></p>
Copy link

Choose a reason for hiding this comment

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

Nice job using the blockquote. Is there better html semantic to denote the author?

<button type="button" class="btn" id="new-quote">New quote</button>
</div>
</body>
</html>
18 changes: 18 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@



// DO NOT EDIT BELOW HERE

// pickFromArray is a function which will return one item, at
Expand All @@ -14,6 +17,7 @@
// Examples of use
// ---------------
// pickFromArray(['a','b','c','d']) // maybe returns 'c'


// You don't need to change this function
function pickFromArray(choices) {
Expand Down Expand Up @@ -491,3 +495,17 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote
let randomQuote = pickFromArray(quotes);
console.log(randomQuote); // maybe logs { quote: "...", author: "..." }
Copy link

Choose a reason for hiding this comment

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

Always remember to remove console.log before pushing your codes. It is a bad practice having this pushed to production.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, thanks, when i see " DO NOT modify this array, otherwise the tests may break!" i just leave it.


const quoteElement = document.getElementById("quote");
const authorElement = document.getElementById("author");
const newquoteButton = document.getElementById("new-quote");

function displayRandomQuote() {
Copy link

Choose a reason for hiding this comment

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

Having a function where you can fetch a quote and update your DOM is good, as it improves code readability and quality. Well-done!

Copy link
Author

Choose a reason for hiding this comment

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

got it

const randomQuote = pickFromArray(quotes);
quoteElement.innerText = `"${randomQuote.quote}"`;
authorElement.innerText = `- ${randomQuote.author}`;
Copy link

Choose a reason for hiding this comment

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

Consider using textContent instead of innerText when setting the quote and author. textContent is generally preferred for performance and consistency because it doesn’t trigger layout calculations and ignores CSS visibility. innerText is useful only when you need to respect rendered styles, which isn’t necessary here since you’re just inserting plain text.

You can read more about innerText and textContent here:
https://www.geeksforgeeks.org/html/difference-between-textcontent-and-innertext/

Copy link
Author

Choose a reason for hiding this comment

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

Ok thanks i will consideded it

}
displayRandomQuote();
newquoteButton.addEventListener("click", displayRandomQuote);
46 changes: 46 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
/** Write your CSS in here **/
body {
margin: 0;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: #4244c7;
font-family: Arial, sans-serif;
}
.greeting {
color: #fff;
margin-bottom: 50px;
font-size: 24px;
}
.quote-box {
background: #f0f0f0;
padding: 20px 30px;
border-radius: 10px;
text-align: center;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

blockquote {
margin: 0 0 10px;
font-size: 28px;
color: #080706c7;
font-style: italic;
font-weight: bold;
}
.author {
margin: 0 0 15px;
color: #1d0daf;
font-size: 20px;
font-weight: bold;
}

.btn {
background: #4244c7;
color: #fff;
border: none;
padding: 8px 16px;
border-radius: 20px;
cursor: pointer;
}
.btn:hover { background: #eb2f48; }