Skip to content

Commit

Permalink
Merge pull request #1 from bloominstituteoftechnology/fix
Browse files Browse the repository at this point in the history
Fix
  • Loading branch information
Ladrillo authored Dec 4, 2023
2 parents 28e4011 + 59a8694 commit 103b2e3
Showing 1 changed file with 98 additions and 105 deletions.
203 changes: 98 additions & 105 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

<head>
<title>Web Sprint 2 Challenge</title>

<script id="challenge">
// 👉 CHALLENGE 1
function profileActivation(profile, reason) {
Expand All @@ -12,7 +11,7 @@

// 👉 CHALLENGE 2
function mineSweeper(grid, x, y) {

}

// 👉 CHALLENGE 3
Expand All @@ -22,7 +21,7 @@

// 👉 CHALLENGE 4
function scrub(text, forbidden) {

}

// 👉 CHALLENGE 5 (bonus, NOT graded)
Expand All @@ -32,10 +31,16 @@

// 👉 CHALLENGE 6 (bonus, NOT graded)
function diceRolls() {

}
</script>

// 🧪 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;
Expand All @@ -61,13 +66,12 @@
#outcome {
font-size: 3rem;
}

</style>
</head>

<body>
<h1>Web Sprint 2 Challenge </h1>
<p>❗ See the last script tag for instructions on completing your Challenge</p>
<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>
Expand Down Expand Up @@ -95,105 +99,94 @@ <h1>Web Sprint 2 Challenge </h1>
</form>
<!-- widgets end -->

<!-- The first script tag loads a library called lodash that helps with testing -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
<script>
// 🧪 TESTS, do not make any changes below this line ===================
// 🧪 TESTS, do not make any changes below this line ===================
// 🧪 TESTS, do not make any changes below this line ===================
globalThis.challengeVersion = 1
globalThis.profileActivation = profileActivation
globalThis.mineSweeper = mineSweeper
globalThis.booleanize = booleanize
globalThis.scrub = scrub
globalThis.normalizePhoneNumber = normalizePhoneNumber

try {
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')
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)
}
})
<!-- 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])}`)
})
phoneNumInput.oninput = evt => {
normalized.textContent = normalizePhoneNumber(evt.target.value)
}
} catch (err) { console.error(err.stack) }
}
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>

Expand Down

0 comments on commit 103b2e3

Please sign in to comment.