sort names by set instead of by set symbol

This commit is contained in:
marsteralex 2022-08-17 20:50:13 -04:00
parent 6b37ac8e4b
commit ac7cb21a1a

View File

@ -221,7 +221,9 @@ function setUpNewGame() {
artDict = sampledData[0] artDict = sampledData[0]
let randomImages = Object.keys(artDict) let randomImages = Object.keys(artDict)
shuffleArray(randomImages) shuffleArray(randomImages)
let namesList = Array.from(sampledData[1]).sort() let namesList = Array.from(sampledData[1]).sort((a, b) =>
removeSymbol(a).localeCompare(removeSymbol(b))
)
// fill in the new cards and names // fill in the new cards and names
for (let cardIndex = 1; cardIndex <= k; cardIndex++) { for (let cardIndex = 1; cardIndex <= k; cardIndex++) {
let currCard = document.getElementById('card-' + cardIndex) let currCard = document.getElementById('card-' + cardIndex)
@ -239,6 +241,11 @@ function setUpNewGame() {
} }
} }
function removeSymbol(name) {
let arr = name.split('>')
return arr[arr.length - 1]
}
function checkAnswers() { function checkAnswers() {
let score = k let score = k
// show the correct full cards // show the correct full cards
@ -247,12 +254,12 @@ function checkAnswers() {
let incorrect = true let incorrect = true
if (currCard.dataset.name) { if (currCard.dataset.name) {
// remove image text // remove image text
let guess = document let guess = removeSymbol(
.getElementById(currCard.dataset.name) document.getElementById(currCard.dataset.name).innerText
.innerText.split('>') )
let ans = artDict[currCard.dataset.url][0].split('>') let ans = removeSymbol(artDict[currCard.dataset.url][0])
window.console.log(ans, guess) window.console.log(ans, guess)
incorrect = ans[ans.length - 1] !== guess[guess.length - 1] incorrect = ans !== guess
// decide if their guess was correct // decide if their guess was correct
} }
if (incorrect) currCard.classList.add('incorrect') if (incorrect) currCard.classList.add('incorrect')