'use strict'; // keyboard layouts const keyboardLayouts = { 'usQwertyKeyboard' : 'abcdefghijklmnopqrstuvwxyz'.toUpperCase(), 'ruQwertyKeyboard' : 'йцукеёнгшщзхъфывапролджэячсмитьбю'.toUpperCase() } const words = [ 'google', 'speed', 'design', 'forest', 'forever', 'love', 'horizon', 'defect' ]; // game variables let gameWord = words[Math.floor(Math.random() * words.length)].toUpperCase(); let gameAnswered = new Array(gameWord.length + 1).join('-'); let lives = 6; // init keyboard function generateKeyboard(layout) { let keyboardHtmlStr = ''; layout.split('').forEach(function(letter) { keyboardHtmlStr = keyboardHtmlStr + ''; }) let keyboard = document.querySelector("#keyboard"); keyboard.classList.remove('is-hidden'); document.querySelector("#keyboard").innerHTML = keyboardHtmlStr; } // letter click action function letterClick(letter) { let charButton = document.getElementById(letter); charButton.disabled = true; let indices = []; let idx = gameWord.split('').indexOf(letter) if (idx == -1) { wrongLetter(); updateStats('stLetterClick'); return; } while (idx != -1) { indices.push(idx); idx = gameWord.split('').indexOf(letter, idx + 1); } indices.forEach(function(item, indices) { let wordArray = gameAnswered.split('') wordArray[item] = letter; gameAnswered = wordArray.join(''); document.querySelector("#word").innerHTML = gameAnswered; updateStats('stCorrLetter'); }) if (gameAnswered.split('').indexOf('-') == -1) { updateStats('stWinWords'); document.querySelector('#keyboard').innerHTML = '\ \