covenants commited on
Commit
1f834e3
·
1 Parent(s): 3fd0b84

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +93 -17
index.html CHANGED
@@ -1,19 +1,95 @@
1
  <!DOCTYPE html>
2
  <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <!DOCTYPE html>
2
  <html>
3
+ <head>
4
+ <title>Wordle Game</title>
5
+ </head>
6
+ <body>
7
+ <h1>Welcome to Wordle!</h1>
8
+ <p>Try to guess the hidden word by selecting the correct letters.</p>
9
+ <p id="word"></p>
10
+ <p>Guess a letter:</p>
11
+ <input type="text" id="guess" maxlength="1">
12
+ <button onclick="guessLetter()">Submit</button>
13
+ <p id="feedback"></p>
14
+ <p id="guesses"></p>
15
+
16
+ <script>
17
+ // List of words to choose from
18
+ var words = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape"];
19
+ // Maximum number of guesses allowed
20
+ var maxGuesses = 6;
21
+ // Current state of the game
22
+ var word;
23
+ var guessedLetters = new Set();
24
+ var guessesLeft;
25
+ var wordDisplay = "";
26
+
27
+ // Function to start a new game
28
+ function newGame() {
29
+ // Select a random word from the list
30
+ word = words[Math.floor(Math.random() * words.length)];
31
+ guessedLetters.clear();
32
+ guessesLeft = maxGuesses;
33
+
34
+ // Display the initial state of the game
35
+ wordDisplay = "";
36
+ for (var i = 0; i < word.length; i++) {
37
+ wordDisplay += "_ ";
38
+ }
39
+ document.getElementById("word").innerHTML = wordDisplay;
40
+ document.getElementById("guesses").innerHTML = "Guesses left: " + guessesLeft;
41
+ }
42
+
43
+ // Function to update the display when a letter is guessed
44
+ function updateDisplay() {
45
+ wordDisplay = "";
46
+ for (var i = 0; i < word.length; i++) {
47
+ if (guessedLetters.has(word[i])) {
48
+ wordDisplay += word[i] + " ";
49
+ } else {
50
+ wordDisplay += "_ ";
51
+ }
52
+ }
53
+ document.getElementById("word").innerHTML = wordDisplay;
54
+ document.getElementById("guesses").innerHTML = "Guesses left: " + guessesLeft;
55
+ }
56
+
57
+ // Function to check if the game is over
58
+ function checkGameOver() {
59
+ if (wordDisplay.indexOf("_") == -1) {
60
+ alert("Congratulations, you win!");
61
+ newGame();
62
+ } else if (guessesLeft == 0) {
63
+ alert("Sorry, you lose! The word was: " + word);
64
+ newGame();
65
+ }
66
+ }
67
+
68
+ // Function to handle a letter guess
69
+ function guessLetter() {
70
+ var guess = document.getElementById("guess").value.toLowerCase();
71
+ if (guess.length == 1 && /[a-z]/.test(guess)) {
72
+ if (guessedLetters.has(guess)) {
73
+ document.getElementById("feedback").innerHTML = "You already guessed that letter.";
74
+ } else if (word.indexOf(guess) == -1) {
75
+ guessesLeft--;
76
+ document.getElementById("feedback").innerHTML = "Incorrect guess.";
77
+ updateDisplay();
78
+ checkGameOver();
79
+ } else {
80
+ guessedLetters.add(guess);
81
+ document.getElementById("feedback").innerHTML = "Correct guess!";
82
+ updateDisplay();
83
+ checkGameOver();
84
+ }
85
+ } else {
86
+ document.getElementById("feedback").innerHTML = "Please enter a valid letter.";
87
+ }
88
+ document.getElementById("guess").value = "";
89
+ document.getElementById("guess").focus();
90
+ }
91
+
92
+ // Start a new game when the page loads
93
+ newGame();
94
+ </script>
95
+ </body