-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (24 loc) · 863 Bytes
/
Copy pathapp.js
File metadata and controls
30 lines (24 loc) · 863 Bytes
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
// import words array & jumble function
import { jumble } from "./utils.js";
import { words } from "./words.js";
const jumbledWord = document.getElementById("jumbled-word");
const guessInput = document.getElementById("guess-input");
const submitButton = document.getElementById("submit-button");
const resultMessage = document.getElementById("result");
let currentWord = "";
function setup() {
currentWord = words[Math.floor(Math.random() * words.length)];
jumbledWord.textContent = jumble(currentWord);
}
function handleGuess(event) {
event.preventDefault();
const guess = guessInput.value;
if (guess === currentWord) {
resultMessage.textContent = "You win!";
} else {
resultMessage.textContent = "Sorry, try again.";
}
}
setup();
submitButton.addEventListener("click", handleGuess);
//function called jumble and a const called words