-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
38 lines (30 loc) · 887 Bytes
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WASM Guessing Game</title>
</head>
<body>
<h1>Guess the number!</h1>
<input type="number" id="userGuess">
<button id="guessBtn">Guess</button>
<p id="result"></p>
<script type="module" defer>
import init, {Game} from './pkg/wasm_guessing_game.js';
async function run() {
await init();
window.game = Game.new();
}
function makeGuess() {
const userGuess = parseInt(document.getElementById('userGuess').value);
const result = game.guess(userGuess);
document.getElementById('result').innerText = result;
}
window.addEventListener('load', () => {
document.getElementById('guessBtn').addEventListener('click', makeGuess);
});
run();
</script>
</body>
</html>