-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
46 lines (40 loc) · 1.92 KB
/
script.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
let words = new Array()
words[0] = new Array()
words[1] = new Array()
words[2] = new Array()
words[3] = new Array()
let area = document.getElementById("sentences")
function presets() {
words[0].push("masked","unethical","idealistic","secretive","untrustworthy","bumbling","reserved","pitiful","heroic","diabolical")
words[1].push("Jeff","Moe","Maurice","Nialliv","Cupman","Blake","Shades","Hood","Collector","Assistant")
words[2].push("betrays","steals","throws","attacks","regrets","forgets","eats","hacks","shoots","lies")
words[3].push("skillfully","easily","terribly","wistfully","secretly","quickly","ashamedly","strangely","selfishly","well")
}
function sentence() {
if (words[0].length == 0 || words[1].length == 0 || words[2].length == 0 || words[3].length == 0) {
alert("Not enough words loaded!")
} else {
let phrase = ("The " + words[0][Math.floor(Math.random()*words[0].length)] + " " + words[1][Math.floor(Math.random()*words[1].length)] + " " + words[2][Math.floor(Math.random()*words[2].length)] + " " + words[3][Math.floor(Math.random()*words[3].length)])
area.append(phrase)
area.append(document.createElement("br"))
}
}
function submitword(e) {
if (e.key === 'Enter') {
newword = this.value
newword = newword.substring(0, newword.length - 1)
this.value = ""
if (newword.length > 0) {
this.nextSibling.nextSibling.innerHTML += "\xa0\xa0\xa0\xa0" + newword
category = words[parseInt(this.id)]
category.push(newword)
}
}
}
function clear() {
area.innerHTML = ""
}
document.getElementById("genbutton").addEventListener("click",sentence)
document.getElementById("prebutton").addEventListener("click",presets)
document.getElementById("clrbutton").addEventListener("click",clear)
document.querySelectorAll(".submissions").forEach(function (textbox) {textbox.addEventListener("keyup",submitword)})