diff --git a/app.js b/app.js index 303beda..87b133e 100644 --- a/app.js +++ b/app.js @@ -11,6 +11,7 @@ form.addEventListener('submit', (e) => { const userInArray = findById(formData.get('name'), existingUsers); + // great job holding onto existing users here and checking to see if they have a session running! if (!existingUsers.length) { const user = { name: formData.get('name'), diff --git a/game/game-utils.js b/game/game-utils.js index 5ef2a40..4356322 100644 --- a/game/game-utils.js +++ b/game/game-utils.js @@ -49,6 +49,7 @@ function makeShuffledDeck() { copiedDeck.sort(function (a, b) { return 0.5 - Math.random(); }); // eslint-disable-line const halfDeck = copiedDeck.splice(0, cardPairs); const fullDeck = halfDeck.concat(halfDeck); + // great work figuring out the sorting method! const shuffledDeck = fullDeck.sort(function (a, b) { return 0.5 - Math.random(); }); // eslint-disable-line return shuffledDeck; } @@ -80,12 +81,12 @@ export function renderCard(card) { // On click, flips card over and checks for a match function flipCard() { - if (clicked[0] !== this) { + if (clicked[0] !== this) { // woah--does `this` refer to a clicked element or something? seems like it should refer to the function this.classList.toggle('is-flipped'); const audio = document.querySelector('#flip-audio'); audio.volume = 0.1; audio.play(); - clicked.push(this); + clicked.push(this); // surprised to see `this`--again, seems like `this` refers to the function if (clicked.length === 2) { gameBoard.classList.add('noClick'); tryCount++; @@ -109,6 +110,7 @@ function flipCard() { clicked = []; } else { resetGameButton.classList.add('noClick'); + // nice setTimeout! setTimeout(() => { clicked[0].classList.toggle('is-flipped'); clicked[1].classList.toggle('is-flipped'); @@ -126,6 +128,7 @@ function checkEndGame() { if (matched === cardPairs) { const winAudio = document.querySelector('#win-audio'); winAudio.volume = 0.2; + // nice work getting the audio to play conditionally this! winAudio.play(); const winMessage = document.createElement('p'); @@ -149,6 +152,7 @@ export function setUserScore() { const currentUsersArray = getUsers(); for (let user of currentUsersArray) { if (user.name === currentUser.name) { + // very cool function! nice work using global state in an interesting way user.levels[currentUser.game].push(tryCount); } } diff --git a/results/results-utils.js b/results/results-utils.js index 9b2ff1c..6bc3a13 100644 --- a/results/results-utils.js +++ b/results/results-utils.js @@ -25,6 +25,8 @@ export function renderScore(userDataLevels) { } const sorted = userDataLevels.sort(function (a, b) { return a - b; }) // eslint-disable-line ; + + // so it returns the highest "userDataLevel"? this is a bit tough to parse; I'd want to see some more human-readable variables here if I were maintaining this code return sorted[0]; } diff --git a/results/results.js b/results/results.js index d0601fc..9a1c10c 100644 --- a/results/results.js +++ b/results/results.js @@ -15,11 +15,10 @@ for (let user of userData) { // On score board page, if no user info is saved in local storage, play again button will redirect home page playAgainButton.addEventListener('click', () => { const currentUser = getCurrentUser(); - if (currentUser === null) { - window.location = '../index.html'; - } else { - window.location = '../game/'; - } + + window.location = !currentUser + ? '../index.html' + : '../game/'; }); // brings user back to home page diff --git a/test/example.test.js b/test/example.test.js index 4d48330..456bd9d 100644 --- a/test/example.test.js +++ b/test/example.test.js @@ -4,6 +4,7 @@ const test = QUnit.test; // renderScoreLine test test('render table line based on user data in local storage; returns "-" for empty array, and returns lowest(best) score for multiple entries', (expect) => { + // would have like to see some more tests in here. I think the reubric asked for at least 3? const userData = { name: 'Casey', levels: