Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
8 changes: 6 additions & 2 deletions game/game-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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++;
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions results/results-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

9 changes: 4 additions & 5 deletions results/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/example.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down