Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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
export default async function main(req: Request): Promise<Response> {
const styles = `
<style>
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
body {
background: linear-gradient(90deg, #f3ec78, #af4261);
font-family: 'Press Start 2P', cursive;
color: white;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.board {
display: grid;
grid-template-columns: repeat(5, 50px);
gap: 10px;
}
.cell {
width: 50px;
height: 50px;
border: 2px solid white;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
transition: transform 0.2s, background-color 0.2s;
color: white;
}
.cell.correct {
background-color: green;
}
.cell.present {
background-color: yellow;
color: black;
}
.cell.absent {
background-color: gray;
}
.board.shake .cell {
animation: shake 0.5s;
}
.board .cell.filled:not(.correct):not(.present):not(.absent) {
background-color: black;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-5px); }
75% { transform: translateX(5px); }
}
input {
display: none;
}
</style>
`;
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weird Wordle</title>
${styles}
</head>
<body>
<div class="board"></div>
<input id="input" type="text" maxlength="5">
<script>
const WORD = 'CRAZY';
let currentRow = 0;
function createBoard() {
const board = document.querySelector('.board');
for (let i = 0; i < 30; i++) {
const cell = document.createElement('div');
cell.classList.add('cell');
board.appendChild(cell);
}
}
function handleInput(event) {
const input = event.target;
const value = input.value.toUpperCase();
input.value = '';
if (value.length !== 5) return;
const board = document.querySelector('.board');
const rowStart = currentRow * 5;
const rowEnd = rowStart + 5;
let correctCount = 0;
for (let i = 0; i < 5; i++) {
const cell = board.children[rowStart + i];
cell.textContent = value[i];
cell.classList.add('filled');
if (value[i] === WORD[i]) {
janpaul123-valle_tmp_17314117069468577415194390357787.web.val.run
July 15, 2024