-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnormal.js
More file actions
132 lines (112 loc) · 4.26 KB
/
Copy pathnormal.js
File metadata and controls
132 lines (112 loc) · 4.26 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
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
//
// ---------------------------------------------------------
// Hi! Are you here to find the answer to Challenge 3?
// Scroll down to the "Read the JavaScript" section, your answer is hidden there!
// ---------------------------------------------------------
//
window.addEventListener("DOMContentLoaded", (event) => {
// Remove hard mode startTime
localStorage.removeItem("startTime");
//
// ---------------------------------------------------------
// Hidden password challenge
// ---------------------------------------------------------
//
const hiddenPasswordSubmitBtn = document.querySelector("button.hidden-password");
const hiddenPasswordField = document.querySelector("input.hidden-password");
if (hiddenPasswordSubmitBtn) {
hiddenPasswordSubmitBtn.addEventListener("click", event => {
if (hiddenPasswordField.value == hiddenPasswordField.getAttribute("data-password")) {
window.location.href = "/challenges/normal/bat.html";
} else {
throwError();
};
});
};
//
// ---------------------------------------------------------
// Disabled button challenge
// ---------------------------------------------------------
//
const disabledBtn = document.querySelector("button[disabled]");
if (disabledBtn) {
disabledBtn.addEventListener("click", event => {
window.location.href = "/challenges/normal/cow.html";
});
};
//
// ---------------------------------------------------------
// Read the JavaScript challenge
// ---------------------------------------------------------
//
if (document.body.id == "js-challenge") {
document.addEventListener("dblclick", function (e) {
window.location.href = "/challenges/normal/duck.html";
});
};
//
// ---------------------------------------------------------
// Local Storage challenge
// ---------------------------------------------------------
//
const storagePasswordSubmitBtn = document.querySelector("button.storage");
const storagePasswordField = document.querySelector("input.storage");
const storagePassword = "h0ud1n1";
if (storagePasswordSubmitBtn) {
localStorage.setItem("password", storagePassword);
storagePasswordSubmitBtn.addEventListener("click", event => {
const password = localStorage.getItem("password");
if (storagePasswordField.value == password) {
window.location.href = "/challenges/normal/gecko.html";
} else {
throwError();
}
});
} else {
localStorage.removeItem("password", storagePassword);
};
//
// ---------------------------------------------------------
// JavaScript Console challenge
// ---------------------------------------------------------
//
const consolePasswordSubmitBtn = document.querySelector("button.console");
const consolePasswordField = document.querySelector("input.console");
const consolePassword = `pr${1+2}st${0}`;
let clickCount = 0;
let clickMax = 3;
if (consolePasswordSubmitBtn) {
console.log("-------------------------------------------------")
console.log(`Click the submit button on this page ${clickMax - clickCount} times to receive the password.`)
consolePasswordSubmitBtn.addEventListener("click", event => {
if (consolePasswordField.value == consolePassword) {
window.location.href = "/challenges/normal/hare.html";
} else {
throwError();
if (clickCount >= 2) {
console.log(`The password is ${consolePassword}`)
} else {
clickCount++;
console.log(`Click the submit button on this page ${clickMax - clickCount} more times to receive the password.`)
};
};
});
};
});
//
// ---------------------------------------------------------
// Styles challenge
// ---------------------------------------------------------
//
const stylesPasswordSubmitBtn = document.querySelector("button.styles-btn");
const stylesPasswordField = document.querySelector("input.styles-password");
const stylesPassword = "hocus pocus"
if (stylesPasswordSubmitBtn) {
stylesPasswordSubmitBtn.addEventListener("click", event => {
if (stylesPasswordField.value == stylesPassword) {
window.location.href = "/challenges/normal/jellyfish.html";
} else {
throwError();
};
});
};