Randomize default code

This commit is contained in:
2023-11-02 21:50:54 +01:00
parent b083271b92
commit 383ae9184d

View File

@@ -1,12 +1,20 @@
import './style.css';
const CODE = import.meta.env.VITE_KEYPAD_CODE || '1234';
const CODE = import.meta.env.VITE_KEYPAD_CODE || generateCode(4);
let builder = '';
const display = document.getElementById('display') as HTMLDivElement;
const light = document.getElementById('light') as HTMLDivElement;
const keypad = document.getElementById('keypad') as HTMLDivElement;
function generateCode(len: number): string {
let code = '';
for (let i = 0; i < len; i++) {
code += Math.floor(Math.random() * 10).toString();
}
return code;
}
function resetCode() {
builder = '';
display.innerText = '_'.repeat(CODE.length);