-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
106 lines (82 loc) · 3.06 KB
/
index.html
File metadata and controls
106 lines (82 loc) · 3.06 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<html>
<img width="100" height="100" src="https://clipartix.com/wp-content/uploads/2016/09/1-dice-clipart-free-clipart-images-image-3.png" class="attachment-full size-full" alt="1 dice clipart free clipart images image 3" loading="lazy" srcset="https://clipartix.com/wp-content/uploads/2016/09/1-dice-clipart-free-clipart-images-image-3.png 784w, https://clipartix.com/wp-content/uploads/2016/09/1-dice-clipart-free-clipart-images-image-3-167x170.png 167w" sizes="(max-width: 784px) 100vw, 784px" >
<p>my code block html</p>
<script>
var dice, sumOfArray, rolls, item, array;
// Describe this function...
function display_rolls() {
if(--window.LoopTrap <= 0) throw "Infinite loop.";
let element_list = document.getElementById('list');
element_list.replaceChildren();
rolls.forEach((item) => {
let new_li = document.createElement('li');
new_li.innerText = item;
element_list.appendChild(new_li);
});
}
<!-This is a new comment -->
<new comment>
// Describe this function...
function total11() {
if(--window.LoopTrap <= 0) throw "Infinite loop.";
if (sum_of_array() == 11) {
let element_info = document.getElementById('info');
element_info.innerText = 'You Won';
let element_total = document.getElementById('total');
element_total.innerText = rolls.reduce((a,b) => a+b, 0);
} else if (sum_of_array() > 11) {
let element_info2 = document.getElementById('info');
element_info2.innerText = 'You Lost';
let element_total2 = document.getElementById('total');
element_total2.innerText = rolls.reduce((a,b) => a+b, 0);
} else if (sum_of_array() < 11) {
let element_info3 = document.getElementById('info');
element_info3.innerText = 'Keep playing';
let element_total3 = document.getElementById('total');
element_total3.innerText = rolls.reduce((a,b) => a+b, 0);
}
}
function randomInt(n) {
// Return a random number from in [0, n[
return Math.floor(Math.random()*n);
}
function randomMember(arr) {
// Return a random member of the array
return arr[randomInt(arr.length)]
}
// Describe this function...
function show_picture() {
if(--window.LoopTrap <= 0) throw "Infinite loop.";
}
// Describe this function...
function sum_of_array() {
if(--window.LoopTrap <= 0) throw "Infinite loop.";
sumOfArray = rolls.reduce((a,b) => a+b, 0);
return sumOfArray;
}
dice = [1, 2, 3, 4, 5, 6];
rolls = [];
display_rolls();
document.getElementById('button_roll').addEventListener('click', (event) => {
rolls.push(randomMember(dice));
display_rolls();
total11();
});
document.getElementById('button_restart').addEventListener('click', (event) => {
rolls = [];
display_rolls();
total11();
});
document.getElementById('button_remove').addEventListener('click', (event) => {
rolls.pop();
display_rolls();
total11();
});
</script>
<p>So far you have rolled:</p>
<ul id="list"></ul>
<button id="button_roll">Roll the dice</button>
<p>Total: <span id="total">0</span>. <span id="info">Keep playing!</span></p>
<button id="button_remove">Remove the last roll</button>
<button id="button_restart">Start again</button>
</html>