-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
100 lines (92 loc) · 2.49 KB
/
index.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
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
100
let colorDiv = document.getElementById('color')
let startButton = document.getElementById('start')
let finished = document.getElementById('finished-indicator')
let timer = document.getElementById('timer')
let boxLabel = document.getElementById('indicator')
let trialIndicator = document.getElementById('trial-indicator')
//Stopwatch
function time(seconds){
timer.textContent = JSON.stringify(seconds)
wait(1000).then(()=>{
if(seconds > 1){
seconds--
time(seconds)
}else{
return
}
})
}
let color = 1;
let count = 0;
let globalCount = 0;
//this function is responsible for switching the colors and text for each trial
function update(){
boxLabel.textContent = 'Color Indicator'
trialIndicator.textContent = `Trial ${globalCount + 1}`
if(count < 9){
if(color === 1){
time(5)
colorDiv.style.backgroundColor = 'green'
wait(5000).then(()=>{
color--;
count++
update()
})
}
if(color === 0){
colorDiv.style.backgroundColor = 'red'
time(3)
wait(3000).then(()=>{
color++;
count++
update()
})
}
}
if(count === 9){
globalCount++
colorDiv.style.backgroundColor = '#f8f9fa'
timer.textContent = ''
finished.textContent = 'Finished!'
wait(1000).then(()=>{
color = 1
count = 0
finished.textContent = ''
subjectBreak()
wait(31000).then(()=>{
if(globalCount <= 7){
update()
}else{
boxLabel.textContent = ''
timer.textContent = ''
trialIndicator.textContent = ''
finished.textContent = 'Full Test Complete! Please refresh the page.'
return
}
})
})
}
}
function subjectBreak(){
boxLabel.textContent = 'Break Time!'
time(30)
return
}
function darker(){
startButton.style.backgroundColor = '#69b578'
}
function lighter(){
startButton.style.backgroundColor = '#3a7d44'
}
function wait(ms){
return new Promise(resolve => setTimeout(resolve, ms));
}
startButton.addEventListener('mousedown', (e)=>{
e.preventDefault()
darker()
update()
})
startButton.addEventListener('mouseup', (e)=>{
e.preventDefault()
lighter()
})