-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathham.js
More file actions
85 lines (81 loc) · 2.7 KB
/
ham.js
File metadata and controls
85 lines (81 loc) · 2.7 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
(function(window){
"use strict";
var ham = function(parameter){
return new Library(parameter);
}
var Library = function(parameter){
this.pigs = [];
this.cookedHam = 0;
const elements = document.querySelectorAll(parameter);
console.log("Garry found " + elements.length + " pig(s)");
for(var i=0;i<elements.length;i++){
this.pigs.push(elements[i]);
}
return this;
}
Library.prototype = {
cook: function(){
if(this.pigs.length > 0){
this.cookedHam += 1;
this.pigs.pop();
console.log("Garry makes cooked ham");
}else{
console.log("Garry dont have any pigs");
}
return this;
},
eat: function(){
if(this.cookedHam > 0){
this.cookedHam = this.cookedHam - 1;
console.log("Garry eats the cooked ham");
}else{
console.log("Garry can't seem to find his cooked ham");
}
return this;
},
hunt: function(parameter){
const hunting = document.querySelectorAll(parameter);
console.log("Garry slaugthered " + hunting.length + " pig(s)");
for(var i=0;i<hunting.length;i++)
this.pigs.push(hunting[i]);
return this;
},
hidePigs: function(){
console.log("Garry hides his pigs");
for (var i = 0; i < this.pigs.length; i++) {
this.pigs[i].style.display = 'none';
}
return this;
},
showPigs: function(){
console.log("Garry shows his pigs");
for (var i = 0; i < this.pigs.length; i++) {
console.log(this.pigs[i])
this.pigs[i].style.display = 'block';
}
return this;
},
piggyBath: function(){
console.log("Garry gives his pigs a nice bath");
for (var i = 0; i < this.pigs.length; i++) {
this.pigs[i].innerHTML = "";
}
return this;
},
throwDirt: function(parameter, text){
if(text){
const pigs = document.querySelectorAll(parameter);
console.log("Garry plays around with his pigs in the dirt");
for (var i = 0; i < pigs.length; i++) {
pigs[i].innerHTML = text;
}
}else{
console.log("It is a shiny day, Garry cant seem to find any dirt to throw at his pigs");
}
return this;
}
}
if(!window.ham){
window.ham = ham;
}
})(window)