Skip to content

Commit 4ecaeb3

Browse files
author
Arthur
committed
Final commit of the app
1 parent 7f47bff commit 4ecaeb3

5 files changed

Lines changed: 104 additions & 9 deletions

File tree

‎Sprint-3/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"homepage": "https://github.com/CodeYourFuture/Module-Data-Groups#readme",
2525
"devDependencies": {
2626
"@testing-library/dom": "^10.4.0",
27-
"@testing-library/jest-dom": "^6.6.3",
27+
"@testing-library/jest-dom": "^6.9.1",
2828
"@testing-library/user-event": "^14.6.1",
2929
"jest": "^30.0.4",
3030
"jest-environment-jsdom": "^30.0.4"

‎Sprint-3/quote-generator/index.html‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Title here</title>
77
<script defer src="quotes.js"></script>
8+
<link rel="stylesheet" href="style.css">
89
</head>
910
<body>
10-
<h1>hello there</h1>
11-
<p id="quote"></p>
12-
<p id="author"></p>
11+
<div class="card">
12+
<div class="quote-container">
13+
14+
<span class="quote-mark">“</span><p id="quote"></p>
15+
<p id="author"></p> </div>
16+
17+
<div class="button-container">
18+
1319
<button type="button" id="new-quote">New quote</button>
20+
</div>
1421
</body>
22+
1523
</html>
24+
25+

‎Sprint-3/quote-generator/package.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
"bugs": {
1414
"url": "https://github.com/CodeYourFuture/CYF-Coursework-Template/issues"
1515
},
16-
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme"
16+
"homepage": "https://github.com/CodeYourFuture/CYF-Coursework-Template#readme",
17+
"devDependencies": {
18+
"jest-environment-jsdom": "^30.4.1"
19+
}
1720
}

‎Sprint-3/quote-generator/quotes.js‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,42 @@
11
// DO NOT EDIT BELOW HERE
2-
2+
//
33
// pickFromArray is a function which will return one item, at
44
// random, from the given array.
5-
//
5+
66
// Parameters
77
// ----------
88
// choices: an array of items to pick from.
99
//
10+
1011
// Returns
1112
// -------
1213
// One item at random from the given array.
1314
//
15+
1416
// Examples of use
1517
// ---------------
1618
// pickFromArray(['a','b','c','d']) // maybe returns 'c'
1719

1820
// You don't need to change this function
19-
function pickFromArray(choices) {
20-
return choices[Math.floor(Math.random() * choices.length)];
21+
22+
function pickFromArray(quotes) {
23+
return quotes[Math.floor(Math.random() * quotes.length)];
2124
}
25+
// First condition: When a person click the button, it should generate back a quote;
26+
27+
function updateWebpageWithQuote() {
28+
const elem = document.querySelector("#quote");
29+
const elem2 = document.querySelector("#author");
30+
31+
// store into the variable
32+
const elem3 = pickFromArray(quotes);
33+
elem.innerText = elem3.quote;
34+
elem2.innerText = elem3.author;
35+
}
36+
37+
// Second condition: when a person enter the website, it should have a quote appear;
38+
39+
// Third condition: when a person clicks the button each time, it should have different quote. .
2240

2341
// A list of quotes you can use in your app.
2442
// DO NOT modify this array, otherwise the tests may break!
@@ -490,4 +508,9 @@ const quotes = [
490508
},
491509
];
492510

511+
const buttonElem = document.querySelector("#new-quote");
512+
513+
buttonElem.addEventListener("click", updateWebpageWithQuote);
514+
updateWebpageWithQuote();
515+
493516
// call pickFromArray with the quotes array to check you get a random quote

‎Sprint-3/quote-generator/style.css‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,60 @@
11
/** Write your CSS in here **/
2+
3+
body{
4+
5+
background-color:orange;
6+
margin:0;
7+
display: flex;
8+
min-height: 100vh;
9+
justify-content: center;
10+
align-items:center;
11+
}
12+
13+
14+
.card{
15+
background-color: white;
16+
padding:30px;
17+
border-radius: 8px;
18+
max-width: 500px;
19+
20+
}
21+
22+
.quote-container{
23+
display: flex;
24+
align-items: flex-start;
25+
gap: 15px;
26+
}
27+
28+
.quote-mark{
29+
font-size: 90px;
30+
color: orange;
31+
line-height: 1;
32+
font-family: sans-serif;
33+
34+
}
35+
36+
37+
#quote{
38+
color: orange;
39+
font-size: 24px;
40+
}
41+
42+
#author{
43+
color: orange;
44+
font-size: 24px;
45+
}
46+
47+
.button-container{
48+
display:flex;
49+
justify-content:flex-end;
50+
min-height: 50px;
51+
52+
}
53+
54+
#new-quote{
55+
background-color: orange;
56+
color:white;
57+
border: none;
58+
}
59+
60+

0 commit comments

Comments
 (0)