-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstroop.js
76 lines (76 loc) · 2.32 KB
/
stroop.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
const vm = Vue.createApp({
delimiters: ['[[', ']]'],
data() {
return {
fontColor: 'black',
colorText:"藍色",
correct: 0,
fail: 0,
done: 0,
timer: 0
}
},
methods:{
red: function(){
this.checkAnswer("紅色")
},
blue: function(){
this.checkAnswer("藍色")
},
green: function(){
this.checkAnswer("綠色")
},
black: function(){
this.checkAnswer("黑色")
},
yellow: function(){
this.checkAnswer("黃色")
},
showAlert(bottonText){
swal({
title: 'Stroop Game',
icon: "success",
content: {
element: "input",
attributes: {
placeholder: "輸入計時秒數"
}
},
button: {
text: bottonText,
},
closeOnClickOutside: false,
}).then((value) => {
this.countdown(value);
this.correct = 0, this.fail = 0, this.done = 0;
});
},
checkAnswer(colorParam){
var textArray = ["紅色","藍色","綠色","黑色","黃色"];
var colorArray = ["red","blue","green","black","rgb(203, 203, 0)"];
var r = Math.floor(Math.random() * 5);
this.colorText = textArray[r];
console.log(this.fontColor);
textArray[colorArray.indexOf(this.fontColor)] == colorParam ? this.correct++ : this.fail++;
this.done = this.correct + this.fail;
this.getRandomColor()
},
getRandomColor(){
var colorArray = ["red","blue","green","black","rgb(203, 203, 0)"];
var r = Math.floor(Math.random() * 5);
this.fontColor = colorArray[r];
},
countdown(seconds) {
var interval = setInterval(()=>{
this.timer = seconds;
if(--seconds < 0){
clearInterval(interval);
this.showAlert("R e s t a r t")
}
}, 1000);
}
},
mounted(){
this.showAlert("S t a r t")
}
}).mount('#app')