-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
71 lines (66 loc) · 1.67 KB
/
main.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
var dollarFormatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
});
function animateTheCow() {
playMooSound();
var elem = document.getElementById("cowImg");
var id = setInterval(frame, 100);
var angle = 0;
elem.style.transform = "rotate(" + angle + "deg)";
function frame() {
console.log('Animating ...');
if (angle < 180) {
angle += 20;
console.log("rotating to " + angle + "deg");
elem.style.transform = "rotate(" + angle + "deg)";
}
else {
clearInterval(id);
}
}
}
function playMooSound() {
document.getElementById("mooSound").play()
}
const app = Vue.createApp({
data: function() {
return{
subtotal: 0.0,
tipPct: 10,
tipUSD: "$0.00",
total: 0.0,
totalUSD: "$0.00",
showMouseover: false,
mouseoverText: "Tip the cow!",
cowTipped: false,
cowAngle: 0
}
},
methods: {
clickTheCow() {
console.log('you clicked the cow!!');
if(this.cowTipped) {
this.cowTipped = false;
this.cowAngle = 0;
var elem = document.getElementById("cowImg");
elem.style.transform = "rotate(0deg)";
}
else {
this.total = Math.round(this.subtotal*(1 + this.tipPct/100) * 100) / 100;
this.totalUSD = dollarFormatter.format(this.total);
this.cowTipped = true;
animateTheCow()
}
},
updateTip(newTip) {
console.log('the tip changed to: ' + newTip);
this.tipPct = newTip;
this.tipUSD = dollarFormatter.format(this.subtotal*this.tipPct/100);
},
mouseoverCow() {
console.log("it's hover time!")
this.showMouseover = true;
}
}
})