use random word

This commit is contained in:
Starbeamrainbowlabs 2022-02-02 02:11:45 +00:00
parent 778f66209f
commit 23fc7196fa
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 15 additions and 4 deletions

View file

@ -1,15 +1,23 @@
"use strict";
import mutate from './mutate.mjs';
import { mutate, random_item } from './mutate.mjs';
let display_options = 3;
let initial_words = [
"rockets",
"cheese",
"treasure",
"island"
]
window.addEventListener("load", (_event) => {
const el_starting_word = document.querySelector("#starting-word");
const el_starting_regen = document.querySelector("#starting-regen");
if(el_starting_word.value.length > 0)
if(el_starting_word.value.length === 0)
el_starting_word.value = random_item(initial_words);
handle_starting_keyup();
el_starting_word.addEventListener("keyup", handle_starting_keyup);

View file

@ -7,7 +7,7 @@ function random_item(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
export default function(word) {
function mutate(word) {
const chars = word.toLowerCase().split("");
const targetpos = Math.floor(Math.random() * word.length);
@ -47,3 +47,6 @@ export default function(word) {
}
return chars.join("");
}
export default mutate;
export { mutate, random_item };