-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwow.html
More file actions
48 lines (42 loc) · 1.36 KB
/
wow.html
File metadata and controls
48 lines (42 loc) · 1.36 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Word Generator</title>
</head>
<body>
<input type="text" id="inputText" placeholder="Enter text" />
<button onclick="generateWords()">Generate</button>
<div id="output"></div>
<script>
async function fetchWords() {
const response = await fetch('https://raw.githubusercontent.com/dwyl/english-words/master/words.txt');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const text = await response.text();
return text.split('\n');
}
async function generateWords() {
let input = document.getElementById("inputText").value.toUpperCase();
let output = document.getElementById("output");
output.innerHTML = "Loading...";
try {
const words = await fetchWords();
output.innerHTML = "";
for (let i = 0; i < input.length; i++) {
let foundWords = words.filter(word => word.toUpperCase().startsWith(input[i]));
if (foundWords.length > 0) {
let word = foundWords[Math.floor(Math.random() * foundWords.length)];
output.innerHTML += word + "<br>";
} else {
output.innerHTML += input[i];
}
}
} catch (error) {
output.innerHTML = "Failed to fetch words. " + error.message;
}
}
</script>
</body>
</html>