-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
151 lines (137 loc) · 5.17 KB
/
scripts.js
File metadata and controls
151 lines (137 loc) · 5.17 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* Data Catalog Project Starter Code - SEA Stage 2
*
* This file is where you should be doing most of your work. You should
* also make changes to the HTML and CSS files, but we want you to prioritize
* demonstrating your understanding of data structures, and you'll do that
* with the JavaScript code you write in this file.
*
* The comments in this file are only to help you learn how the starter code
* works. The instructions for the project are in the README. That said, here
* are the three things you should do first to learn about the starter code:
* - 1 - Change something small in index.html or style.css, then reload your
* browser and make sure you can see that change.
* - 2 - On your browser, right click anywhere on the page and select
* "Inspect" to open the browser developer tools. Then, go to the "console"
* tab in the new window that opened up. This console is where you will see
* JavaScript errors and logs, which is extremely helpful for debugging.
* (These instructions assume you're using Chrome, opening developer tools
* may be different on other browsers. We suggest using Chrome.)
* - 3 - Add another string to the titles array a few lines down. Reload your
* browser and observe what happens. You should see a fourth "card" appear
* with the string you added to the array, but a broken image.
*
*/
// This is an array of strings (career titles)
const careers = [
{
title: "Author",
description: "Writes books and articles.",
image: "https://m.media-amazon.com/images/I/51D6fgwoWRL._SL1500_.jpg",
goals: [
"Write a bestselling novel",
"Publish articles in top magazines",
],
quotes: ["Your story is your power"],
},
{
title: "Software Engineer",
description: "Develops software applications.",
image: "https://i.pinimg.com/736x/c9/7b/a9/c97ba98b802694a97a548160c9e324ef.jpg",
goals: [
"Build a successful app",
"Work on innovative technology",
],
quotes: ["Code like you could be the next Steve Jobs"],
},
{
title: "Content Creator",
description: "Creates engaging content for various platforms.",
image: "img/IMG_1792.jpg",
goals: [
"Grow a loyal audience",
"Produce high-quality content",
],
quotes: ["Your creativity is your currency"],
},
{
title: "Nurse",
description: "Provides medical care and support to patients.",
image: "img/nurse.jpg",
goals: [
"Deliver compassionate patient care",
"Stay updated on medical advancements",
],
quotes: ["Not all heroes wear capes some wear scrubs"],
},
{
title: "Teacher",
description: "Educates and inspires students.",
image: "https://i.pinimg.com/736x/11/35/4f/11354f25567e8b47e3e2b990ac11228c.jpg",
goals: [
"Foster a love for learning",
"Support students' academic growth",
],
quotes: ["Teaching is the greatest act of optimism"],
},
{
title: "Recruiter",
description: "Connects job seekers with employers.",
image: "https://i.pinimg.com/736x/ea/c8/31/eac83105eb521f004de7c4900f4ef7de.jpg",
goals: [
"Match candidates with the right jobs",
"Build strong relationships with clients",
],
quotes: ["Your network is your networth"],
},
];
// This funtion is used to show the cards on the page
function showCards(filteredCareers = careers) {
const container = document.getElementById("card-container");
const template = document.querySelector(".card");
const noResults = document.getElementById("no-results");
container.innerHTML = ""; // Clear old cards
if (filteredCareers.length === 0) {
noResults.style.display = "block";
} else {
noResults.style.display = "none";
}
filteredCareers.forEach((career) => {
const nextCard = template.cloneNode(true);
editCardContent(nextCard, career);
nextCard.style.display = "block"; // Make visible
nextCard.addEventListener("click", () => {
alert(career.quotes.join(" "));
});
container.appendChild(nextCard);
});
}
// This funtion Edit content of the card based on career data
function editCardContent(card, career) {
card.querySelector(".card-title").textContent = career.title;
card.querySelector(".card-description").textContent = career.description;
card.querySelector(".card-image").src = career.image;
card.querySelector(".card-goals").innerHTML = career.goals
.map((goal) => `<li>${goal}</li>`)
.join("");
card.querySelector(".card-quote").textcontent = career.quotes.join(" ");
}
function searchCareer() {
const searchInput= document.getElementById("search-input").value.toLowerCase();
const filtered = careers.filter((career) =>
career.title.toLowerCase().includes(searchInput)
);
showCards(filtered);
}
// This function is used to filter the cards based on the search input
document.addEventListener("DOMContentLoaded", () => {
showCards(); // Show all careers initially
const searchInput = document.getElementById("search-input");
searchInput.addEventListener("input", () => {
const searchTerm = searchInput.value.toLowerCase();
const filtered = careers.filter((career) =>
career.title.toLowerCase().includes(searchTerm)
);
showCards(filtered);
});
});