-
-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory Pair Game #344
base: main
Are you sure you want to change the base?
Memory Pair Game #344
Conversation
Added some changes with fixes and improvements |
Feedback collected, issues fixed accordingly to remarks by other students.
|
This issue has been automatically marked as stale because there were no activity during last 14 days. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. А. Чому так? Б. Що робити, якщо в піарі нема оновлень, оскільки не зрозуміло, що треба зробити? В. А якщо я все зробив(ла) і це ментор не рев'юває мої зміни?
Г. Хіба недостатньо того, що я додав(ла) коміт із змінами? Традиційна пропозиція: задай питання по вищенаписаному в студентському чаті. |
Self checks done, please, remove stale label. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! Please take a look at the comments.
Small tip - if we want to compare two elements we can simply use
function isElementsMatched (first, second) { return first.name === second.name }
currentCardPair: [], | ||
totalTries: 0, | ||
}; | ||
const allGameCards = shuffleCards([...cards, ...cards]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems allCards or shuffledCards will be enough here, to make it consistent with shuffleCards
renderCards(allGameCards, cardsMenu); | ||
|
||
function shuffleCards(cardsArr) { | ||
for (let i = cardsArr.length - 1; i > 0; i--) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks sort
array method is the best choice here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did You mean that Fisher–Yates shuffle is overkill to shuffle game cards? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a built-in sort
method in JS for this purpose, no need to reinvent the wheel, also it is much better for code readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you can leave it, I changed my mind :))
} | ||
|
||
function sleep(milliseconds) { | ||
return new Promise((resolve) => setTimeout(resolve, milliseconds)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need async operation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to create some kind of custom delay function instead of repeating setTimeout all the time. This is solution I came up with and thats why I use async - await later. I haven't figured out how to do that in another way yet (except using setTimeout in every place where I currently used my sleep() function.
cardsList.innerHTML = cardsHTML; | ||
} | ||
|
||
function sleep(milliseconds) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess cards won't sleep, please try rename a function :)
} | ||
|
||
function checkCardsMatch() { | ||
return states.firstFlippedCard.isEqualNode(states.secondFlippedCard); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why so a complicated approach? I guess better compare name of the cards, even for performance reasons
} | ||
|
||
function restartGame() { | ||
location.reload(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clumsy method :))
|
||
let cardsBlocked = false; | ||
|
||
cardsMenu.addEventListener("click", async function flipCards({ target }) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please explain why do you need async here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I unterstood remark properly. Without async-await it all breaks and does not work as expected.
I tried to account all the recommendations and remarks, but some questions still left (answered in comments above). |
This issue has been automatically marked as stale because there were no activity during last 14 days. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. А. Чому так? Б. Що робити, якщо в піарі нема оновлень, оскільки не зрозуміло, що треба зробити? В. А якщо я все зробив(ла) і це ментор не рев'юває мої зміни?
Г. Хіба недостатньо того, що я додав(ла) коміт із змінами? Традиційна пропозиція: задай питання по вищенаписаному в студентському чаті. |
Memory Pair Game
Demo | Code base
The code is submitted in a dedicated feature branch.
Only code files are submitted.
Please, review.