-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcookies.js
More file actions
69 lines (51 loc) · 1.37 KB
/
cookies.js
File metadata and controls
69 lines (51 loc) · 1.37 KB
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
window.onload = function(){
// MODEL=====================================================
function Cookie(){
this.type = "chocolate chip";
this.softness = 6;
this.remaining = 3
};
//MODEL METHODS ===============================================
Cookie.prototype = {
eat: function(){
this.remaining -= 1;
},
dipInMilk: function(){
this.softness += 2;
},
anythingLeft: function(){
if (this.remaining > 0) { return "There's more" }
else { return "It's all gone" };
}
};
//MODEL FACTORY
createCookie = function(){
return new Cookie();
};
var el = document.getElementsByClassName("new");
el[0].addEventListener("click", addCookie, false)
var otherel = document.getElementsByClassName("eat");
otherel[0].addEventListener("click", eatAllCookies, false)
};
var cookieJar = []
// PSEUDO CONTROLLER ===============================
function addCookie(){
var cookie = createCookie()
cookieJar.push(cookie);
console.log(cookie);
console.log(cookieJar);
// $('.new').html("<img src="cookie"></img>")
}
function eatAllCookies(){
console.log(cookieJar)
for(var i = 0; i < cookieJar.length; i++){
cookieJar[i].eat();
console.log(cookieJar[i].remaining);
console.log(cookieJar[i].anythingLeft());
}
}
// VIEW !!! ===========================================
// cookieView = {}
// cookiewView.prototype = function(){
// printCookie:
// }