-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.js_1st_try
50 lines (38 loc) · 1.02 KB
/
application.js_1st_try
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
function Die(numSides) {
this.numSides = numSides;
};
Die.prototype.addDie = function() {
$('.dice').append('<div class="die">0</div>');
};
Die.prototype.rollAllDie = function(k, die) {
var value = Math.floor((Math.random()*6)+1);
$(die).text(value);
};
Die.prototype.getAllDie = function() {
console.log(this);
$('die').each(function(k, die) {
this.rollAllDie(k,die);
});
};
function bindEvents(play_die) {
$('#roller button.add').on('click', function() {
play_die.addDie();
});
$('#roller button.roll').on('click', function() {
play_die.getAllDie();
});
};
$(document).ready(function() {
// $('#roller button.add').on('click', function() {
// console.log("WAT")
// $('.dice').append('<div class="die">0</div>');
// });
// $('#roller button.roll').on('click', function() {
// $('.die').each(function(k, die) {
// var value = Math.floor((Math.random()*6)+1);
// $(die).text(value);
// });
// });
var play_die = new Die(6);
bindEvents(play_die);
});