forked from Kpeguero16/Grassroots
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
99 lines (82 loc) · 2.55 KB
/
Copy pathscript.js
File metadata and controls
99 lines (82 loc) · 2.55 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
// Reads and saves JSON data
const json = require("./job-postings.json");
// Creates arrays to store listings and categories
const listings = [];
const categories = [];
var hasLogIn = false;
var loginError = false;
// Populates arrays
for(let i = 0; i < 3; i++)
{
category = json[i];
categories.push(category["category"]);
listings_available = category["jobs"];
for(let j = 0; j < listings_available.length; j++)
{
listings.push(listings_available[j]);
}
}
console.log(categories);
// Prints all listings that has input in it.
function search(input)
{
for(let i = 0; i < listings.length; i++)
{
// Searches for the term with the matching input
const listing = listings[i];
if(listing["title"] === input || listing["poster"] === input || listing["description"].includes(input) ||
listing["city"] === input || listing["pay"].includes(input))
{
// Output area
console.log(listing);
}
}
}
// Loads 3 random listings
function load() {
// Has a collection of already used nums
// Ensures no listing is used again
const used_nums = [];
for (let i = 0; i < 3; i++) {
// Generates random number and checks if it's already used
const num = Math.floor(Math.random() * (listings.length));
if (used_nums.includes(num)) {
// Causes the for-loop to go back and breaks the flow
i--;
continue;
}
used_nums.push(num);
// Gets file with the randomly generated number
const listing = listings[num];
// Output Area
console.log(listing);
}
}
function login(form)
{
event.preventDefault();
if(form.user.value !== "" && form.password.value !== "")
{
window.location.replace("index.html");
} else {
window.location.replace("loginfail.html");
}
}
fetch('job-postings.json')
.then(response => response.json()) // Parse the JSON from the response
.then(data => {
// The JSON data is now stored in the `data` variable
console.log(data); // For debugging
// Pass `data` to parser here
})
.catch(error => console.error('Error fetching the JSON file:', error));
function redirectToJobs() {
window.location.href = "job.html"; // Replace with the relative path to your HTML file
}
function redirectToMain() {
window.location.href = "index.html"; // Replace with the relative path to your HTML file
}
function throwToError()
{
window.location.href="loginfail.html";
}