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
}

i guess this answers your question:

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.

Thanks for sharing the link!

I am definitely going to go through the challenge. :grinning:

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 :sweat_smile: 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 :sweat_smile: 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 :sweat_smile:

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