Files
freeCodeCamp/curriculum/challenges/english/08-coding-interview-prep/project-euler/problem-1-multiples-of-3-and-5.english.md
Randell Dawson c25916c9a2 fix(curriculum): changed test text to use should for Coding Interview Prep - part 2 of 2 (#37766)
* fix: changed test text to use should

* fix: corrected typo

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>

* fix: removed extra period

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>

* fix: removed extra period

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>

* fix: removed extra period

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>

* fix: removed extra period

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>

* fix: corrected typo

Co-Authored-By: Tom <20648924+moT01@users.noreply.github.com>
2019-11-20 10:01:31 -05:00

1.5 KiB

id, challengeType, title, forumTopicId
id challengeType title forumTopicId
5900f36e1000cf542c50fe80 5 Problem 1: Multiples of 3 and 5 301722

Description

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below the provided parameter value number.

Instructions

Tests

tests:
  - text: <code>multiplesOf3and5(1000)</code> should return 233168.
    testString: assert.strictEqual(multiplesOf3and5(1000), 233168);
  - text: <code>multiplesOf3and5(49)</code> should return 543.
    testString: assert.strictEqual(multiplesOf3and5(49), 543);
  - text: <code>multiplesOf3and5(19564)</code> should return 89301183.
    testString: assert.strictEqual(multiplesOf3and5(19564), 89301183);
  - text: <code>multiplesOf3and5(8456)</code> should return 16687353.
    testString: assert.strictEqual(multiplesOf3and5(8456), 16687353);

Challenge Seed

function multiplesOf3and5(number) {
  // Good luck!
  return true;
}

multiplesOf3and5(1000);

Solution

const multiplesOf3and5 = (number) => {
  var total = 0;

  for(var i = 0; i < number; i++) {
    if(i % 3 == 0 || i % 5 == 0) {
      total += i;
    }
  }
  return total;
};