DEV Community

Cover image for Day 1 of JavaScriptmas - Candies Solution

Day 1 of JavaScriptmas - Candies Solution

Keep moving forward. Learn well not learn fast.
・1 min read

The 1st challenge is to count how many candies of each child gonna be get if someone has X candies.

for instance, if granpa have 10 candies and there are 3 grandchildren.
How many each child going to be get candy?
So 10/3 is 3.33. In general, each child has 3 candies.
Total candies for children will be 3*3 is 9.

So there is JavaScript the solution

function candies(children, candy) {
    let eaten = Math.floor(candy/children);
    return children * eaten;
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

Forem Open with the Forem app