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[1].id] == this.turned[0].id;
20 if (!match && !this.turned[0].classList.contains('bad')) {
21 put(this.turned[0], '.bad'); // indicate failure on first card
26 // lock both as correct
27 this.turned.forEach(card => put(card, '.good![onclick]'));
32 // fold back earlier cards
33 this.turned.splice(0, 2)
34 .forEach(card => put(card, '!.turn!.bad'));
38 this.dataurl = '/data/wordpairs.json';
39 fetch(this.dataurl).then(res => res.json()).then(pairs => {
42 this.form = document.getElementById('quiz');
43 this.cards = Object.entries(pairs).flat()
44 .map(e => e.toString())
45 .sort(() => {return .5 - Math.random()}) // shuffle
46 this.cards.forEach(word => {
48 'figure>img[src=$]<', `/data/word/en/${word}.jpg`,
49 {onclick: e => this.turn(e), id: word}