-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
80 lines (73 loc) · 1.41 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
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
let randomInt = ()=>{
return Math.random().toString().slice(2,4)
}
Vue.component('tile', {
props:['n'],
template: '<div @click="onClicked">{{ n }}</div>',
methods:{
onClicked:function(){
scoreboard.update(this.n)
}
},
data: function () {
return {
n: this.n
}
}
})
Vue.component('status_bar', {
props:['Z','t'],
template: '<div class="status_bar"> <span style="position:absolute;z-index:3">{{ Z }}:{{ t }}</span></div>',
methods:{
},
data: function () {
return {
t: this.t
}
}
})
Vue.component('guess', {
props:['g'],
template: ' <div> </div> ',
methods:{
},
data: function () {
return {
n: this.g
}
},
mounted:function(){
this.$vnode.elm.style.height=this.n+'%'
}
})
var scoreboard= new Vue({
el: '#app',
data: {
Tries:0,
TargetValue:randomInt(),
guesses:[],
Difference:0,
values:new Array(8).fill(0).map(el=> randomInt()),
},
methods:{
update: function (s) {
this.guesses.push(s)
this.Tries+=1
},
},
computed: {
current_score: function () {
if(this.guesses.length){
let total = this.guesses.reduce((a,b)=>parseInt(b)+parseInt(a))
let avg = total/this.guesses.length
this.Difference = Math.abs((this.TargetValue-avg)).toFixed(2)
return avg.toFixed(2)
}
this.Difference = this.TargetValue
return 0
},
notes:function(){
return this.guesses.map(el=>getNote(el))
}
}
})