# JavaScript question challenge ambiguous

x children have got y pieces of chocolate. They want to eat as much as chocolate as they can, but each child must eat exactly the same amount of chocolate as any other child. Determine how many pieces of chocolate will be eaten by all the children together. Individual pieces of chocolate cannot be split.

for example: x = 3, y=10, the output should be chocolate(x, y) = 9. Each child will eat 3pieces, so the answer should be 9.

Please someone should help with solution to this challenge. Thank you.

What do you have so far? How do you want to approach this problem?

1 Like

x children have got y pieces of chocolate. They want to eat as much as chocolate as they can, but each child must eat exactly the same amount of chocolate as any other child. Determine how many pieces of chocolate will be eaten by all the children together. Individual pieces of chocolate cannot be split.

for example: x = 3, y=10, the output should be chocolate(x, y) = 9. Each child will eat 3pieces, so the answer should be 9.

You just copy-pasted your original post.

Just visualise the situation. Thereâ€™s three children sitting in a circle and between them is a pile of ten chocolate bars.

Step 1: Each of them grabs one. Total chocolates left: 7. Total chocolates taken: 3.
Step 2: Each of them grabs one. Total chocolates left: 4. Total chocolates taken: 6.
Step 3: Each of them grabs one. Total chocolates left: 1. Total chocolates taken: 9.
Step 4: Not enough chocolates left for three children. Thus return total chocolates taken:

``````function chocolate(x,y) {
return 9
}
``````

REDACTED
what it does is that you need to divide the number of pieces by the number of children and then you see how many pieces each child gets, but because you want to have the total pieces then itâ€™s the total pieces minus whatâ€™s left and canâ€™t be divided evenly (for integer)

piece of cake! (literally XD)
also, if you understood this then and it helped you please mark this as solution because Iâ€™m trying to level up trust level and this really helps

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original posterâ€™s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please donâ€™t just post your solution for the sake of sharing it.

Please be aware that we also do not want users who are â€śreputation farmingâ€ť. Your trust level has been temporarily locked.

I redacted your posted code, as this is part of the Free Code Camp 24 Days of Javascriptmas, and just handing out answers is not very sporting.

I am definitely going to go through the challenge.

oh, I didnâ€™t know this is actually a thing, I thought it was just some school work that this person needs to do at 2AM and Iâ€™d be happy to get a direct answer instead of some hints if i was in his/her place, if itâ€™s a part of the curriculm then I donâ€™t post solutions immediately

oh, I didnâ€™t know this is actually a thing, I thought it was just some school work that this person needs to do at 2AM and Iâ€™d be happy to get a direct answer instead of some hints if i was in his/her place, if itâ€™s a part of the curriculm then I donâ€™t post solutions immediately, my intention wasnâ€™t to just get reputation, first time iâ€™m asking for this (because it doesnâ€™t feel really well with almost 1k posts read and many replies and only 2-3 marked as soultionâ€¦) and i almost get bannedâ€¦

Hey @harel_avv!

I appreciate your enthusiasm and activities on the forum but you shouldnâ€™t worry about the numbers. I donâ€™t look at my numbers at all and I basically live on the forum

Just enjoy helping people and growing as a teacher.

We do not give out answers on the freeCodeCamp forum

Giving answers to home work does not help the user learn how to figure things out without direct answers. It is always better to give hints to get a user to think about how to solve a problem.

2 Likes