Back to Freecodecamp

Challenge 40: Photo Storage

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68b1f72371a5ac895ac70a02.md

latest1.1 KB
Original Source

--description--

Given a photo size in megabytes (MB), and hard drive capacity in gigabytes (GB), return the number of photos the hard drive can store using the following constraints:

  • 1 gigabyte equals 1000 megabytes.
  • Return the number of whole photos the drive can store.

--hints--

numberOfPhotos(1, 1) should return 1000.

js
assert.equal(numberOfPhotos(1, 1), 1000);

numberOfPhotos(2, 1) should return 500.

js
assert.equal(numberOfPhotos(2, 1), 500);

numberOfPhotos(4, 256) should return 64000.

js
assert.equal(numberOfPhotos(4, 256), 64000);

numberOfPhotos(3.5, 750) should return 214285.

js
assert.equal(numberOfPhotos(3.5, 750), 214285);

numberOfPhotos(3.5, 5.5) should return 1571.

js
assert.equal(numberOfPhotos(3.5, 5.5), 1571);

--seed--

--seed-contents--

js
function numberOfPhotos(photoSizeMb, hardDriveSizeGb) {

  return photoSizeMb;
}

--solutions--

js
function numberOfPhotos(photoSizeMb, driveSizeGb) {
  const driveSizeMb = driveSizeGb * 1000;
  return Math.floor(driveSizeMb / photoSizeMb);
}