use random word
This commit is contained in:
parent
778f66209f
commit
23fc7196fa
2 changed files with 15 additions and 4 deletions
14
js/index.mjs
14
js/index.mjs
|
@ -1,16 +1,24 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import mutate from './mutate.mjs';
|
import { mutate, random_item } from './mutate.mjs';
|
||||||
|
|
||||||
let display_options = 3;
|
let display_options = 3;
|
||||||
|
|
||||||
|
let initial_words = [
|
||||||
|
"rockets",
|
||||||
|
"cheese",
|
||||||
|
"treasure",
|
||||||
|
"island"
|
||||||
|
]
|
||||||
|
|
||||||
window.addEventListener("load", (_event) => {
|
window.addEventListener("load", (_event) => {
|
||||||
const el_starting_word = document.querySelector("#starting-word");
|
const el_starting_word = document.querySelector("#starting-word");
|
||||||
const el_starting_regen = document.querySelector("#starting-regen");
|
const el_starting_regen = document.querySelector("#starting-regen");
|
||||||
|
|
||||||
if(el_starting_word.value.length > 0)
|
if(el_starting_word.value.length === 0)
|
||||||
handle_starting_keyup();
|
el_starting_word.value = random_item(initial_words);
|
||||||
|
|
||||||
|
handle_starting_keyup();
|
||||||
|
|
||||||
el_starting_word.addEventListener("keyup", handle_starting_keyup);
|
el_starting_word.addEventListener("keyup", handle_starting_keyup);
|
||||||
el_starting_regen.addEventListener("click", handle_starting_keyup);
|
el_starting_regen.addEventListener("click", handle_starting_keyup);
|
||||||
|
|
|
@ -7,7 +7,7 @@ function random_item(arr) {
|
||||||
return arr[Math.floor(Math.random() * arr.length)];
|
return arr[Math.floor(Math.random() * arr.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function(word) {
|
function mutate(word) {
|
||||||
const chars = word.toLowerCase().split("");
|
const chars = word.toLowerCase().split("");
|
||||||
const targetpos = Math.floor(Math.random() * word.length);
|
const targetpos = Math.floor(Math.random() * word.length);
|
||||||
|
|
||||||
|
@ -47,3 +47,6 @@ export default function(word) {
|
||||||
}
|
}
|
||||||
return chars.join("");
|
return chars.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default mutate;
|
||||||
|
export { mutate, random_item };
|
||||||
|
|
Loading…
Reference in a new issue