checkValidKey(keypress) {

		// only single/new letters go into array, nothing else
		if (!this.userInput.includes(keypress) && keypress.match(/[a-zA-Z]+/g) && this.state === 'playing' && keypress.length === 1) {
			console.warn(keypress.length)
			this.userInput.push(keypress[0].toLowerCase())
			
			// check if the player is correct
			let validKeyArr = this.isCorrectKey(keypress.toLowerCase())

			if (validKeyArr.length > 0) {
				// correct, reveal letter
				validKeyArr.forEach( (el, index) => {
					el.html.insertAdjacentHTML('beforeend', `<p class='zoom-in-bounce'>${el.key}</p>`)
					el.html.querySelector('.letter-placeholder').remove()
					this.score++
				})
			} else {
				this.attempts--
				this.animateTitle()
			}

			// show to the player
			let userInputCopy = this.userInput.slice()
			this.playerLetter.innerHTML = `<p>Your guesses: ${userInputCopy.join(', ').toUpperCase()}</p>`
		}

		this.gameState()
		// update the attempts message
		document.querySelector('#attempts > p').innerHTML = this.stateMsg
	}
// checks if the keypress can go into the array
checks if the keypress can go into the array
checks if the keypress can go into the array
checkValidKey(keypress) {
		if (!this.userInput.includes(keypress) && keypress.match(/[a-zA-Z]+/g) && this.state === 'playing' && keypress.length === 1) {
			console.warn(keypress.length)
			this.userInput.push(keypress[0].toLowerCase())
			let validKeyArr = this.isCorrectKey(keypress.toLowerCase())
			if (validKeyArr.length > 0) {
				validKeyArr.forEach( (el, index) => {
					el.html.insertAdjacentHTML('beforeend', `<p class='zoom-in-bounce'>${el.key}</p>`)
					el.html.querySelector('.letter-placeholder').remove()
					this.score++
				})
			} else {
				this.attempts--
				this.animateTitle()
			}
			let userInputCopy = this.userInput.slice()
			this.playerLetter.innerHTML = `<p>Your guesses: ${userInputCopy.join(', ').toUpperCase()}</p>`
		}
		this.gameState()
		document.querySelector('#attempts > p').innerHTML = this.stateMsg
	}
checkValidKey ( keypress ) { if ( ! this . userInput . includes ( keypress ) && keypress . match ( / [a-zA-Z]+ / g ) && this . state === 'playing' && keypress . length === 1 ) { console . warn ( keypress . length ) this . userInput . push ( keypress [ 0 ] . toLowerCase ( ) ) let validKeyArr = this . isCorrectKey ( keypress . toLowerCase ( ) ) if ( validKeyArr . length > 0 ) { validKeyArr . forEach ( ( el , index ) => { el . html . insertAdjacentHTML ( 'beforeend' , ` ${ el . key } ` ) el . html . querySelector ( '.letter-placeholder' ) . remove ( ) this . score ++ } ) } else { this . attempts -- this . animateTitle ( ) } let userInputCopy = this . userInput . slice ( ) this . playerLetter . innerHTML = ` ${ userInputCopy . join ( ', ' ) . toUpperCase ( ) } ` } this . gameState ( ) document . querySelector ( '#attempts > p' ) . innerHTML = this . stateMsg }
checks if the keypress can go into the array
checks if the keypress can go into the array
// only single/new letters go into array, nothing else // check if the player is correct // correct, reveal letter // show to the player // update the attempts message