This repository was archived by the owner on Jan 3, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathexercise.js
More file actions
79 lines (68 loc) · 2.43 KB
/
exercise.js
File metadata and controls
79 lines (68 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
Task 1
=======
Write JavaScript below that logs:
1. all the "p" element nodes of the document,
--> should log a list of nodes with a length of 6
2. the first div element node
--> should log the ".site-header" node
3. the element with id "jumbotron-text"
--> should log the "#jumbotron-text" node
4. all the "p" elements of contained inside the .primary-content element node
--> should log a list of nodes with a length of 3
*/ let getAllParagraphElements = document.querySelectorAll(
"p"
);
console.log(getAllParagraphElements);
let getDivNode = document.querySelector(".site-header");
console.log(getDivNode);
let getJumbotronText = document.querySelector("#jumbotron-text");
console.log(getJumbotronText);
let getParagraphInsidePrimaryContent = document.querySelectorAll(
".primary-content p"
);
console.log(getParagraphInsidePrimaryContent);
/*
Task 2
======
When a user clicks the 'ALERT' button, an alert box should pop up with the text "Thanks for visiting Bikes for Refugees!"
*/
let clickAlertButton = document.querySelector("#alertBtn");
clickAlertButton.addEventListener("click", function (event) {
alert("Thanks for visiting Bikes for Refugees!");
});
/*
Task 3
=======
Write JavaScript below that changes the background colour of the page when the 'Change colour' button is clicked.
*/
let getChangeColorButton = document.querySelector("#bgrChangeBtn");
getChangeColorButton.addEventListener("click", function (event) {
let colors = ["lightBlue", "Pink", "Yellow"];
document.querySelector("body").style.backgroundColor =
colors[Math.floor(Math.random() * colors.length)];
});
/*
Task 4
======
When a user clicks the 'Add some text' button, a new paragraph should be added below the buttons that says "Read more below."
*/
let getReadMoreButton = document.querySelector("#addTextBtn");
getReadMoreButton.addEventListener("click", function (event) {
let newText = document.createElement("p");
newText.textContent = "New Text Paragraph added";
let displayText = document.querySelector(".buttons");
displayText.append(newText);
});
/*
Task 5
======
When the 'Larger links!' button is clicked, the text of all links on the page should increase.
*/
let getLargerLinks = document.querySelector("#largerLinksBtn");
getLargerLinks.addEventListener("click", function (event) {
let getAllLinks = document.querySelectorAll("a");
for(var i=0;i<getAllLinks.length;i++){
getAllLinks[i].style.fontSize="xx-large";
}
});