janpaul123-valle_tmp_51677002075225245000926769750689.web.val.run
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
89
90
91
92
93
94
95
96
97
98
99
100
// This val creates a simple Wordle game in HTML with funky, visually striking CSS for a unique experience.
// The game logic is implemented in JavaScript, while CSS handles the unique visual styling.
import { Hono } from "npm:hono";
// CSS Styling for the game
const css = `
body {
font-family: 'Comic Sans MS', cursive, sans-serif;
background: linear-gradient(45deg, #ff6f61, #ffcc00, #33cc33, #1e90ff, #ba55d3);
color: #fff;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 10px;
}
.letter {
width: 50px;
height: 50px;
font-size: 2rem;
font-weight: bold;
text-align: center;
line-height: 50px;
border-radius: 10px;
background-color: rgba(0, 0, 0, 0.5);
}
.letter.correct {
background-color: #33cc33;
}
.letter.present {
background-color: #ffcc00;
}
.letter.absent {
background-color: #ff6f61;
}
`;
// HTML and JavaScript for the game
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Crazy Wordle</title>
<style>${css}</style>
</head>
<body>
<div>
<h1>Crazy Wordle</h1>
<div id="board" class="container"></div>
<input type="text" id="guess" maxlength="5" autofocus>
<button onClick="submitGuess()">Submit</button>
</div>
<script>
const WORD = 'CRAZY';
let attempts = 0;
function submitGuess() {
const guess = document.getElementById('guess').value.toUpperCase();
if (guess.length !== 5) {
alert('Please enter a 5 letter word');
return;
}
const board = document.getElementById('board');
const row = document.createElement('div');
row.className = 'row';
for (let i = 0; i < 5; i++) {
const letter = document.createElement('div');
letter.className = 'letter';
letter.textContent = guess[i];
if (guess[i] === WORD[i]) {
letter.classList.add('correct');
} else if (WORD.includes(guess[i])) {
letter.classList.add('present');
} else {
letter.classList.add('absent');
}
row.appendChild(letter);
}
board.appendChild(row);
document.getElementById('guess').value = '';
attempts++;
if (guess === WORD) {
alert('Congratulations! You guessed the word in ' + attempts + ' attempts');
} else if (attempts === 6) {
alert('You failed to guess the word. The correct word was ' + WORD);
}
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 15, 2024