-
Notifications
You must be signed in to change notification settings - Fork 0
/
gut.js
62 lines (52 loc) · 1.64 KB
/
gut.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
52
53
54
55
56
57
58
59
60
61
62
let gravity = 1
let urgency = 1
let tendency = 1
let score = 1
const clearSelected = (className) => {
var elements = document.getElementsByClassName(className)
if (!elements) { return }
for (let index = 0; index < elements.length; index++) {
const hasSelected = elements[index].classList.contains('selected')
if (!hasSelected) { continue }
elements[index].classList.remove('selected')
break
}
}
const addSelected = (element) => element.classList.add('selected')
const getOptionScore = (element) => {
const elementScore = element.querySelector('#option-value').innerText
return parseInt(elementScore, 10)
}
const calcTotal = () => score = gravity * urgency * tendency
const updateScore = () => {
const scoreElement = document.getElementById('score')
scoreElement.textContent = score
}
const calc = () => {
calcTotal()
updateScore()
}
const gravityChanged = (event) => {
const currentElement = event.currentTarget
clearSelected('gravity')
addSelected(currentElement)
const currentGravityScore = getOptionScore(currentElement)
gravity = currentGravityScore
calc()
}
const urgencyChanged = (event) => {
const currentElement = event.currentTarget
clearSelected('urgency')
addSelected(currentElement)
const currentUrgencyScore = getOptionScore(currentElement)
urgency = currentUrgencyScore
calc()
}
const tendencyChanged = (event) => {
const currentElement = event.currentTarget
clearSelected('tendency')
addSelected(currentElement)
const currentTendencyScore = getOptionScore(currentElement)
tendency = currentTendencyScore
calc()
}