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

Module #2 (Tahsina Bintay Azam) #31

Open
wants to merge 4 commits into
base: module-2
Choose a base branch
from

Conversation

tahsina-azam
Copy link

No description provided.

}
setPoison((currentPoison) => [...currentPoison, newPoison]);
}, [isFood, isSnake]);
//removing poison

Choose a reason for hiding this comment

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

since adding poison or a food works similarly, why not create a reusable function addObject that takes in an object type (poison/food) and adds to the appropriate state?

Copy link
Author

Choose a reason for hiding this comment

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

I wonder why I didn't think like that. :"), I will try to add that in the next module.

Copy link
Author

Choose a reason for hiding this comment

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

I tried adding a new function addObject to add poison or food based on the parameter of that function as you suggested. But looks like there's a little problem with that.
antar
Can you please tell me what's the problem here?
My function:
const addObject = useCallback((type) => {
let newObject = getRandomCell();
while (isSnake(newObject) || isFood(newObject)) {
newObject = getRandomCell();
}
if ((type = "food")) {
setFoods((currentFoods) => [...currentFoods, newObject]);
} else {
setPoison((currentPoison) => [...currentPoison, newObject]);
}
});

Copy link
Contributor

Choose a reason for hiding this comment

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

can you push the code? it's not obvious from here what's causing the issues

Copy link
Author

Choose a reason for hiding this comment

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

Sure. you can find that piece of code in module-3 branch in src/components/hooks/snake.js.
#35

Copy link
Author

Choose a reason for hiding this comment

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

@royantar0311 I have pushed the code into
#35 ,
can you tell me what's wrong there?

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.

3 participants