1 class WordMemory extends WordQuiz {
3 let target = click.currentTarget;
4 if (!target.classList.contains('turn')) {
6 this.turned.push(target);
9 else if (this.turned.length < 2) {
13 if (this.turned.length <= 1) {
14 return; // first choice
18 let match = !this.pairs ? this.turned[0].id == this.turned[1].id : (
19 this.pairs[this.turned[0].id] == this.turned[1].id
20 || this.pairs[this.turned[1].id] == this.turned[0].id
22 if (!match && !this.turned[0].classList.contains('bad')) {
23 put(this.turned[0], '.bad'); // indicate failure on first card
28 // lock both as correct
29 this.turned.forEach(card => put(card, '.good![onclick]'));
31 if (Array.from(this.form.children).every(card => card.classList.contains('good'))) {
32 put(this.form, '.good');
37 // fold back earlier cards
38 this.turned.splice(0, 2)
39 .forEach(card => put(card, '!.turn!.bad'));
47 this.dataurl = '/data/wordpairs.json';
48 fetch(this.dataurl).then(res => res.json()).then(pairs => {
57 this.form = document.getElementById('quiz');
61 const formstyle = window.getComputedStyle(this.form)
63 formstyle['grid-template-rows'], formstyle['grid-template-columns']
64 ].map(val => val.match(/ /g).length + 1).reduce((x, y) => x * y) / 2;
65 cards = this.words.splice(0, gridsize || 6).map(row => row[2]);
66 cards.push(...cards.map(val => -val));
69 cards = Object.entries(this.pairs).flat()
70 .map(e => e.toString())
73 cards.shuffle().forEach(word => {
74 let ref = Math.abs(word);
76 'figure>img[src=$]<', `/data/word/en/${ref}.jpg`,
77 {onclick: e => this.turn(e), id: ref, className: word < 0 ? 'mirror' : ''}