Skip to content

Module #2 (Tahsina Bintay Azam)#31

Open
tahsina-azam wants to merge 4 commits intorecruit-org:module-2from
tahsina-azam:module-2
Open

Module #2 (Tahsina Bintay Azam)#31
tahsina-azam wants to merge 4 commits intorecruit-org:module-2from
tahsina-azam:module-2

Conversation

@tahsina-azam
Copy link
Copy Markdown

No description provided.

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

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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