codedamn

Day 18 of #50DaysOfJS

Asked by Purnendu about 2 years ago

1

Hi, I tried day 18 of #50DaysOfJS. Getting results but test cases not passed. Is it a bug? Please help. Code: const totalGrains = (input) => { // Code here let count = 1, total = 1; for(i=1; i<input; i++) { count *= 2; total += count; }
return total; }

const grainsOn = (input) => { // Code here let count = 1; for(j=1; j<input; j++) { count *= 2; } return count; }

console.log(Grains on 5th square: ${grainsOn(5)}); console.log(Total grains upto 5th square: ${totalGrains(5)});

1 Answer

    -1

    For the grainsOn, you can use Math.pow(2, input) which will give the number of grains on a tile.

    For the totalGrains,

    let total = 0; for (let i = 1; i <= 64; i++) total += grainsOn(i);

    @3ddelano

    Delano Lourenco

    @3ddelano

Your answer