Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions fullstack-cert/js-projects/workshop-escape-room/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>
<script src="script.js"></script>
</body>

</html>
86 changes: 86 additions & 0 deletions fullstack-cert/js-projects/workshop-escape-room/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const countdown = () => {
const answerToLifeMeaningUniverse = 42;
for (let i = 120; i > 0; i--) {
if (i === answerToLifeMeaningUniverse) {
return true;
}
}
return false;
}

const patternMatch = (text, pattern) => {
let left = 0;
let right = text.length;
const patternOffset = pattern.length;
while (left < right) {
if (text.slice(left, left + patternOffset) === pattern ||
text.slice(right, right - patternOffset) === pattern) {
return true;
}
left++;
right--;
}
return false;
}

const inputValidator = () => {
let username;
const minLength = 3;
const maxLength = 17;
const isValidLength = username =>
username.length >= minLength && username.length <= maxLength;

do {
username = prompt('Please enter a valid username:');
} while(username === '' || username === null);

return isValidLength(username);
}

const keypad = {
1: {
isLocked: true,
},
2: {
isLocked: true,
},
3: {
isLocked: true,
}
};

const openDoor = keypad => {
let isOpen = true;

if (countdown()) {
keypad[1].isLocked = false;
console.log('Clue 1 solved: keypad 1 unlocked');
}

if (patternMatch('freecodecampfccFREECODECAMP', 'fcc')) {
keypad[2].isLocked = false;
console.log('Clue 2 solved: keypad 2 unlocked');
}

if (inputValidator()) {
keypad[3].isLocked = false;
console.log('Clue 3 solved: keypad 3 unlocked');
}

checkKeypad: {
for (const lockNumber in keypad) {
if (keypad[lockNumber].isLocked) {
isOpen = false;
break checkKeypad;
}
}
}

if (isOpen) {
console.log('Congratulations! You have solved all the puzzles and can now exit!');
} else {
console.log('Access denied. One or more of the locks are still locked. Please check the progressState');
}
}

openDoor(keypad);
Empty file.