Skip to content
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

2048 #544

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

2048 #544

wants to merge 6 commits into from

Conversation

MaksymBevskyi
Copy link

Copy link

@anastasiiavorobiova anastasiiavorobiova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix your issue, use a valid ids: Screenshot 2023-10-24 at 16 15 54

Copy link

@loralevitska loralevitska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost done) Let's improve

  • fix restart button, it doesn't work
    image

Copy link

@nazarmatsevych nazarmatsevych left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, left some comments to be reviewed and fixed

}
}

if (number === 2048) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (number === 2048) {
if (number === 2048) {

Move magic numbers like 2048 to constant

Comment on lines 59 to 66
const hasEmptyCell = () => {
for (let r = 0; r < rows; r++) {
for (let c = 0; c < columns; c++) {
if (board[r][c] === 0) {
return true;
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use a "some" method here to reduce the amount of code a bit

Comment on lines 224 to 264
const slideLeft = () => {
for (let r = 0; r < rows; r++) {
let row = board[r];

row = slide(row);
board[r] = row;

for (let c = 0; c < columns; c++) {
const cell = document.getElementById(`row_${r}-column_${c}`);
const number = board[r][c];

updateCell(cell, number);
}
}

if (hasChanges(initialBoard, board)) {
setCell();
}
};

const slideRight = () => {
for (let r = 0; r < rows; r++) {
let row = board[r];

row.reverse();
row = slide(row);
row.reverse();
board[r] = row;

for (let c = 0; c < columns; c++) {
const cell = document.getElementById(`row_${r}-column_${c}`);
const number = board[r][c];

updateCell(cell, number);
}
}

if (hasChanges(initialBoard, board)) {
setCell();
}
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functions looks similar, i think we can try to combine them

Copy link

@volodymyr-soltys97 volodymyr-soltys97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job 👍
Let's improve your code

@@ -1,3 +1,345 @@
'use strict';

// write your code here
const MAGIC_NUMBER = 2048;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const MAGIC_NUMBER = 2048;
const WINNER_SCORE = 2048;

}

switch (arrow.key) {
case 'ArrowLeft':

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move all these magic words to variables and use it everywhere

Copy link

@anastasiiavorobiova anastasiiavorobiova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!
Screenshot 2023-10-25 at 14 58 45
On first loading, the restart button doesn't work

Copy link

@anastasiiavorobiova anastasiiavorobiova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants