From 2a12aaf7a890e27780770632990f45021ed2ebd8 Mon Sep 17 00:00:00 2001 From: kuznya Date: Mon, 2 Nov 2020 04:25:41 +0200 Subject: [PATCH] app-02 js release --- app-js-02.html | 10 +++++++ index.html | 13 +-------- js/app-js-02.js | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 12 deletions(-) create mode 100644 app-js-02.html create mode 100644 js/app-js-02.js diff --git a/app-js-02.html b/app-js-02.html new file mode 100644 index 0000000..1862a9b --- /dev/null +++ b/app-js-02.html @@ -0,0 +1,10 @@ + + + +nouns for puzzles + + + + + + diff --git a/index.html b/index.html index 475d21d..1862a9b 100644 --- a/index.html +++ b/index.html @@ -5,17 +5,6 @@ - - -
- - -
- + diff --git a/js/app-js-02.js b/js/app-js-02.js new file mode 100644 index 0000000..f1d4b7d --- /dev/null +++ b/js/app-js-02.js @@ -0,0 +1,72 @@ + const write = (s) => { document.write(s); }; + const elem = (id) => document.getElementById(id) + + let wordsList = []; + + const cats = ['easy', 'common', 'uncommon'] + + const renderCheckbox = (cat) => { + write('
' + + `
${cat}
` + + '
\n' + ); + } + + const checkBoxClickHandle = (ctx) => { + ctx.classList.toggle('active') + optionsChanged() + }; + + const renderHeader = () => { + write('\n'); + }; + + const renderApp = () => { + write('
\n'); + renderHeader(); + write(''); + write('
\n'); + }; + + renderApp(); + + const log = elem('log'); + const print = (s) => { + log.value = s + '\n' + log.value + }; + + const getCats = () => { + return cats.filter( v => elem('id_'+v).classList.contains('active')) + }; + + const filterWords = (cats) => { + wordsList = words.filter(v => cats.includes(v.cat) + && !temporary_disabled.includes(v.word)); + }; + + const optionsChanged = () => { + const cats = getCats(); + filterWords(cats); + print(wordsList.length + ' words loaded: ' + cats) + }; + + const commandGen = () => { + const limit = wordsList.length; + if (!limit) { return; } + const index = Math.floor(Math.random() * limit); + const item = wordsList[index]; + print(`${item.word} (${item.cat})`); + }; + + // go! + // const cats1 = getCats() + // console.log(cats1) + + print(`words base from: ${version_date}`); + print(`${temporary_disabled.length} words temporary disabled`); + optionsChanged();