-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
35 lines (30 loc) · 1.11 KB
/
script.js
File metadata and controls
35 lines (30 loc) · 1.11 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
document.querySelector("#search").addEventListener("click", submitHandler);
function submitHandler() {
let userInputDescription = document.getElementById("description").value;
let userInputLocation = document.getElementById("location").value;
fetchJobs(userInputDescription, userInputLocation);
}
function fetchJobs(userInputDescription, userInputLocation) {
let url = new URL(`https://jobs.github.com/positions.json?
description=${userInputDescription}&location=${userInputLocation}`);
fetch(url)
.then((response) => response.json())
.then((data) => {
console.log(data)
displayJobs(data);
});
}
const displayJobs = (data) => {
document.querySelector("#results").innerHTML = data.map(jobListingMapper);
}
const jobListingMapper = (data) => {
const { title, company_logo, company_url, company, description } = data;
return `<div>
<h3>${title}</h3>
<img src="${company_logo} alt="Company Image"/>
<a href="${company_url}">
<p>Company: ${company}</p>
</a>
<p>${description}</p>
</div>`
}