Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<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>
</head>
<body>
<h1>hello there</h1>
<h1>Quote Generator app</h1>
<p id="quote"></p>
<p id="author"></p>
<button type="button" id="new-quote">New quote</button>
Expand Down
7 changes: 6 additions & 1 deletion Sprint-3/quote-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@
"bugs": {
"url": "https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
},
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme"
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
"devDependencies": {
"@testing-library/jest-dom": "^6.9.1",
"jest": "^30.3.0",
"jest-environment-jsdom": "^30.3.0"
}
}
18 changes: 18 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,21 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote

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

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

quoteElement.textContent = randomQuote.quote;
authorElement.textContent = randomQuote.author;
}

// Show a quote when page loads
displayQuote();

// Change quote when button is clicked
document
.getElementById("new-quote")
.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, I have updated it .

35 changes: 35 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
/** Write your CSS in here **/
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
background-color: #f5f5f5;
}

h1 {
color: #333;
}

#quote {
font-size: 24px;
margin: 20px;
font-style: italic;
}

#author {
font-size: 18px;
color: #666;
}

button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border: none;
background-color: #333;
color: white;
border-radius: 5px;
}

button:hover {
background-color: #555;
}
Loading