Still waiting for the New York Times to send me a bogus takedown notice
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
|
let maxtries = 6;
let input = document.querySelector('input');
let win = document.querySelector('#win');
let hint = document.querySelector('#hint');
let attempt = document.querySelector('#attempt');
let exit = false;
let tries = 0;
let answer = "hello";
let len = answer.length;
input.setAttribute("maxlength", len);
hint.innerHTML = "Word is of length: " + len + "</br>";
function letterinstr(c) {
let isin = false;
for (var i = 0; i < len; i++) {
if (c == answer.charAt(i)) {
isin = true;
break;
}
}
return isin;
}
function addGuessDisplay(answer, guess) {
let cat = ""
for (var i = 0; i < len; i++) {
if (guess.charAt(i) != answer.charAt(i) && !(letterinstr(guess.charAt(i))) ) {
cat += '<span style="color: #595959">' + guess.charAt(i) + "</span>";
} else if (guess.charAt(i) != answer.charAt(i) && (letterinstr(guess.charAt(i))) ) {
cat += '<span style="color: #bebe00">' + guess.charAt(i) + "</span>";
} else if (guess.charAt(i) == answer.charAt(i)) {
cat += '<span style="color: #00ff00">' + guess.charAt(i) + "</span>";
}
}
hint.innerHTML += cat + "</br>";
}
function validateInput(str) {
let isvalid = true;
for (var i = 0; i < len; i++) {
let c = str.charAt(i)
if (c.toUpperCase() == c.toLowerCase()) {
isvalid = false;
break;
}
}
return isvalid;
}
function checkAnswer(event) {
event.preventDefault();
if (!exit) {
if (validateInput(input.value)) {
addGuessDisplay(answer, input.value);
tries++;
if (input.value == answer) {
win.innerHTML = "You won!";
exit = true;
} else {
win.innerHTML = "Not quite right!";
}
if (tries >= maxtries && !exit) {
win.innerHTML = "You lost! Better luck next time!";
exit = true;
}
attempt.innerHTML = tries + " attempt";
if (tries > 1) {
attempt.innerHTML += "s";
}
}
}
}
|