console.log('wordle solver ...')
let form = document.querySelector('[name=verify')
let greenLetters = document.querySelectorAll('#greenLetters')
let yellowLetters = document.querySelectorAll('#yellowLetters')
let greyLetters = document.querySelectorAll('#greyLetters')
let wordleSolverData = document.getElementById('wordleSolverData')
let wordleWordCount = document.querySelector('#wordleWordCount')
let wordleSolvererrorMsg = document.querySelector('#wordleSolvererrorMsg')
let wordlesolver_submit = document.getElementById('wordlesolver_submit')
let newWordsLength = 0
let errMessage = document.querySelector('.errMessage')
let wrapper = document.querySelector('.wrapper')
let addMore = document.querySelector('#addMore')
addMore.addEventListener('click', (e) => {
e.preventDefault()
let div = document.createElement('div')
div.classList.add('d-flex')
div.classList.add('mt-2')
for (let i = 20; i <= 24; i++) {
let input = document.createElement('input')
input.type = 'text'
input.setAttribute('maxlength', '1')
input.setAttribute('autocomplete', 'off')
if (i <= 24) {
input.setAttribute('tabIndex', i)
}
let classes = ['wordleSolver-field', 'greyLetters', 'form-control', 'px-5']
input.classList.add(...classes)
input.id = 'greyLetters'
div.append(input)
wrapper.append(div)
}
})
const wordleSolver = async (value, value2, value3, greenWithIndex) => {
try {
let result = ''
wordleWordCount.innerHTML = 'Searching for best possible letters...'
let response = await fetch('/.netlify/functions/wordleSolver', {
method: 'POST',
body: JSON.stringify({
greenLetters: value,
yellowLetters: value2,
greyLetters: value3,
greenWithIndex: greenWithIndex,
}),
})
const data = await response.json()
let ok = true
if (data.length === 0) {
newWordsLength = ''
wordleSolverData.innerHTML = ''
wordleSolvererrorMsg.classList.add('alert-danger')
wordleSolvererrorMsg.innerHTML = 'Sorry!! No words found'
} else {
wordleSolvererrorMsg.classList.remove('alert-danger')
wordleSolvererrorMsg.innerHTML = ''
wordleSolverData.innerHTML = ''
newWordsLength = ''
newWordsLength += data.length
result = data.map((item) => {
if (item.length === 1) {
ok = false
newWordsLength = newWordsLength - 1
} else {
let ScrabbleLetterScore = ScrabbleScore()
sum = 0
item = item.toLowerCase()
for (let i = 0; i < item.length; i++) {
sum += ScrabbleLetterScore[item[i]] || 0 // for unknown characters
}
return `