-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathindex.html
193 lines (174 loc) Β· 7.29 KB
/
index.html
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html lang="en">
<head>
<title>Web Sprint 2 Challenge</title>
<script id="challenge">
// π CHALLENGE 1
function profileActivation(profile, reason) {
}
// π CHALLENGE 2
function mineSweeper(grid, x, y) {
}
// π CHALLENGE 3
function booleanize(obj) {
}
// π CHALLENGE 4
function scrub(text, forbidden) {
}
// π CHALLENGE 5 (bonus, NOT graded)
function normalizePhoneNumber(num) {
}
// π CHALLENGE 6 (bonus, NOT graded)
function diceRolls() {
}
// π§ͺ DO NOT make any changes below this line ===================
globalThis.challengeVersion = 1
globalThis.profileActivation = profileActivation
globalThis.mineSweeper = mineSweeper
globalThis.booleanize = booleanize
globalThis.scrub = scrub
</script>
<style>
.widget {
padding: 0 0 0.5rem 0.65rem;
margin-bottom: 0.5rem;
border: 1px solid black;
border-radius: 0.5rem;
}
.widget p {
font-size: 0.75rem;
font-style: italic;
}
.row>div {
display: inline-block;
background-color: lightgrey;
border: 1px solid grey;
width: 2rem;
height: 2rem;
cursor: pointer;
}
#outcome {
font-size: 3rem;
}
</style>
</head>
<body>
<h1>Web Sprint 2 Challenge </h1>
<p>Open this HTML document in VSCode to find your challenges</p>
<!-- widgets start -->
<section class="widget">
<p>Click on a square! (this widget uses the mineSweeper function)</p>
<div class="row" id="row1">
<div></div>
<div></div>
<div></div>
</div>
<div class="row" id="row2">
<div></div>
<div></div>
<div></div>
</div>
<div class="row" id="row3">
<div></div>
<div></div>
<div></div>
</div>
<span id="outcome"></span>
</section>
<form class="widget">
<p>Type a ten-digit number! (this widget uses the normalizePhoneNumber function)</p>
<input type="text" id="phoneNumInput" maxlength="10" />
<span id="normalized"></span>
</form>
<!-- widgets end -->
<!-- The following script loads from the Internet a library called Lodash that helps with testing -->
<script id="lodash" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
<!-- The following script executes the tests you see when you open the Console in Chrome -->
<script id="tests">
runTests('CHALLENGE 1 - profileActivation', profileActivation, [
[[{ active: true }], 'confirm status manually'],
[[{ active: true }, 'because'], { active: false, reason: 'because' }],
[[{ active: false, reason: 'because' }], { active: true }],
])
runTests('CHALLENGE 2 - mineSweeper', mineSweeper, [
[[[["π₯", "π¦", "π₯"], ["π¦", "π₯", "π₯"], ["π₯", "π¦", "π¦"]], 0, 4], "invalid coordinates"],
[[[["π₯", "π¦", "π₯"], ["π¦", "π₯", "π₯"], ["π₯", "π¦", "π¦"]], 0, 1], "invalid coordinates"],
[[[["π₯", "π¦", "π₯"], ["π¦", "π₯", "π₯"], ["π₯", "π¦", "π¦"]], 1, 4], "invalid coordinates"],
[[[["π¦", "π¦", "π₯"], ["π¦", "π¦", "π¦"], ["π¦", "π¦", "π₯"]], 1, 1], "π¦ π₯³"],
[[[["π¦", "π₯", "π¦"], ["π¦", "π¦", "π¦"], ["π₯", "π¦", "π₯"]], 2, 1], "π₯ π"],
[[[["π₯", "π¦", "π₯"], ["π₯", "π₯", "π¦"], ["π₯", "π₯", "π¦"]], 3, 1], "π₯ π"],
[[[["π₯", "π¦", "π¦"], ["π₯", "π¦", "π₯"], ["π¦", "π¦", "π¦"]], 1, 2], "π₯ π"],
[[[["π₯", "π₯", "π₯"], ["π₯", "π¦", "π₯"], ["π¦", "π₯", "π¦"]], 2, 2], "π¦ π₯³"],
[[[["π₯", "π¦", "π¦"], ["π¦", "π₯", "π₯"], ["π₯", "π₯", "π¦"]], 3, 2], "π₯ π"],
[[[["π₯", "π₯", "π₯"], ["π¦", "π¦", "π₯"], ["π₯", "π₯", "π¦"]], 1, 3], "π₯ π"],
[[[["π₯", "π¦", "π₯"], ["π₯", "π₯", "π₯"], ["π₯", "π¦", "π₯"]], 2, 3], "π¦ π₯³"],
[[[["π₯", "π₯", "π₯"], ["π¦", "π₯", "π₯"], ["π₯", "π₯", "π¦"]], 3, 3], "π¦ π₯³"],
[[[["π₯", "π¦", "π¦"], ["π₯", "π₯", "π¦"], ["π₯", "π₯", "π₯"]], 1, 1], "π₯ π"],
[[[["π₯", "π¦", "π¦"], ["π₯", "π₯", "π¦"], ["π₯", "π₯", "π₯"]], 2, 2], "π₯ π"],
[[[["π₯", "π¦", "π¦"], ["π₯", "π₯", "π¦"], ["π₯", "π₯", "π₯"]], 3, 3], "π₯ π"],
])
runTests('CHALLENGE 3 - booleanize', booleanize, [
[[{ bad1: null }], {}],
[[{ bad1: null, bad2: null }], {}],
[[{ '0123456789': 1 }], 'shorten all prop names to 9 chars or less'],
[[{ a: 1, b: 1 }], { a: true, b: true }],
[[{ a: 0, b: 0 }], { a: false, b: false }],
[[{ a: 1, b: 0, c: null, d: 'Lady Gaga' }], { a: true, b: false, d: 'Lady Gaga' }],
])
runTests('CHALLENGE 4 - scrub', scrub, [
[["out of the silent planet", ["of", "silent"]], "out xx the xxxxxx planet"],
[["out of the silent planet", ["of", "planet"]], "out xx the silent xxxxxx"],
[["the ghost of the navigator", ["the"]], "xxx ghost of xxx navigator"],
[["lost somewhere in time", []], "lost somewhere in time"],
[["aces high", ["high", "aces", "hearts"]], "xxxx xxxx"],
[["", ["high", "aces"]], ""],
])
runTests('CHALLENGE 5 (OPTIONAL) - normalizePhoneNumber', normalizePhoneNumber, [
[["1234567890"], "(123) 456-7890"],
[["1111111111"], "(111) 111-1111"],
[["9876543210"], "(987) 654-3210"],
])
console.log('\nCHALLENGE 6 (OPTIONAL) does not have auto tests - diceRolls')
function runTests(testName, func, tests) {
let results = []
tests.forEach(test => {
const originalArgsList = _.cloneDeep(test[0])
const argsList = test[0]
const expected = test[1]
const actual = func.apply(null, argsList)
results.push([argsList, expected, actual, originalArgsList])
})
console.log('\n' + testName)
if (results.every(result => _.isEqual(result[1], result[2]))) console.log('\tβ
All tests pass')
else if (results.every(result => !_.isEqual(result[1], result[2]))) console.log('\tβ All tests fail')
else results.forEach((result, idx) => {
if (_.isEqual(result[1], result[2])) console.log(`\tβ
Test ${idx + 1} passes`)
else console.log(`\tβ Test ${idx + 1} fails:
${func.name}(${result[3].map(JSON.stringify)})
π should return ${JSON.stringify(result[1])}
π but returns ${JSON.stringify(result[2])}`)
})
}
const gridElems = [Array.from(row1.children), Array.from(row2.children), Array.from(row3.children)]
const squares = ["π₯", "π¦"]
let grid = [[], [], []]
gridElems.forEach((row, idxRow) => {
row.forEach((square, idxSquare) => {
const emoji = squares[Math.floor(Math.random() * 2)]
grid[idxRow].push(emoji)
if (emoji === squares[0]) square.style.backgroundColor = '#ffecec'
else square.style.backgroundColor = '#f2f2ff'
square.onclick = () => {
const x = idxSquare + 1
const y = idxRow + 1
console.log(`\nYou clicked coordinates [${x}, ${y}]`)
outcome.textContent = mineSweeper(grid, x, y)
}
})
})
phoneNumInput.oninput = evt => {
normalized.textContent = normalizePhoneNumber(evt.target.value)
}
</script>
</body>
</html>