scrimba
Solution for day 1 of #javascriptmas
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Solution for day 1 of #javascriptmas
AboutCommentsNotes
Solution for day 1 of #javascriptmas
Expand for more info
main.js
run
preview
console
function candies(children, candy, distributedCandy = 0) {
let remainingCandy = (candy - children);
distributedCandy += children

if (children <= remainingCandy) {
return candies(children, remainingCandy, distributedCandy)
} else {
return distributedCandy
}
}



/**
* Test Suite
*/
describe('candies()', () => {
it('returns ammount of total equal candy to be eaten', () => {
// arrange
const children = 6;
const candy = 20;

// act
const result = candies(children, candy);

// log
console.log("result: ", result);

// assert
expect(result).toBe(18);
});
});
Console
"result: "
,
18
,
/index.html
LIVE