forked from Thinkful-Ed/starter-national-parks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
76 lines (60 loc) · 2.12 KB
/
index.js
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
console.log(document);
const heading = document.querySelector("h1");
console.log(heading);
const descriptions = document.querySelectorAll(".description-display");
for (let desc of descriptions.values()) {
let content = desc.innerText;
console.log(content);
if (content.length > 250) {
content = content.slice(0, 250);
content = content + "...";
}
desc.innerText = content;
console.log(content);
}
const ratings = document.querySelectorAll(".rating-display .value");
for (let rating of ratings) {
let ratingValue = parseFloat(rating.innerText);
if (ratingValue > 4.7) {
rating.classList.add("high-rating");
rating.classList.remove("value");
}
console.log(ratingValue);
}
const parks = document.querySelectorAll(".park-display");
const numberParks = parks.length;
const newElement = document.createElement("div");
newElement.innerText = `${numberParks} exciting parks to visit`;
newElement.classList.add("header-statement");
const header = document.querySelector("header");
header.appendChild(newElement);
//code to remove element from DOM
// const main = document.querySelector("main");
// const park = main.querySelector(".park-display");
//main.removeChild(park);
const firstBtn = document.querySelector("button");
firstBtn.addEventListener("click", (event) => {
console.log("You clicked the button", event);
});
const allBtns = document.querySelectorAll(".rate-button");
allBtns.forEach((btn) => {
btn.addEventListener("click", (event) => {
console.log(event.target);
});
});
allBtns.forEach((btn) => {
btn.addEventListener("click", (event) => {
const park = event.target.parentNode;
park.style.backgroundColor = "#c8e6c9";
});
});
const nameSorter = document.querySelector("#name-sorter");
nameSorter.addEventListener("click", (event) => {
event.preventDefault();
console.log("You clicked the name sorter");
});
console.log("Before!");
window.addEventListener("DOMContentLoaded", (event) => {
console.log("Loaded!");
});
console.log("After!");