-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.js
51 lines (39 loc) · 1.26 KB
/
generator.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
let enhancers
let technologies
let titles
function registerLoadHander() {
document.body.addEventListener('click', generate);
}
async function load() {
// load buzzwords
await loadArrays();
console.log(enhancers)
console.log(technologies)
console.log(titles)
// fill page
generate()
}
function generate() {
// pick random of each
let random_enhancer = getRandomElement(enhancers)
let random_technology = getRandomElement(technologies)
let random_title = getRandomElement(titles)
let fusion = random_enhancer + " " + random_technology + " " + random_title
console.log("new title: "+fusion)
// store in page
document.getElementById("bingo").innerText = fusion
}
function getRandomElement(json_array) {
return json_array[Math.floor(Math.random()*json_array.length)];
}
async function loadArrays() {
await fetch("enhancers.json")
.then(result => result.json())
.then(loaded_enhancers => enhancers = loaded_enhancers)
await fetch("technologies.json")
.then(result => result.json())
.then(loaded_technologies => technologies = loaded_technologies)
await fetch("titles.json")
.then(result => result.json())
.then(loaded_titles => titles = loaded_titles)
}