2018-09-30 22:01:58 +00:00
|
|
|
---
|
|
|
|
id: 5900f36e1000cf542c50fe80
|
|
|
|
title: 'Problem 1: Multiples of 3 and 5'
|
2020-11-27 18:02:05 +00:00
|
|
|
challengeType: 5
|
2019-08-05 16:17:33 +00:00
|
|
|
forumTopicId: 301722
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: problem-1-multiples-of-3-and-5
|
2018-09-30 22:01:58 +00:00
|
|
|
---
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --description--
|
2020-02-28 12:39:47 +00:00
|
|
|
|
2018-09-30 22:01:58 +00:00
|
|
|
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.
|
2020-02-28 12:39:47 +00:00
|
|
|
|
|
|
|
Find the sum of all the multiples of 3 or 5 below the provided parameter value `number`.
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --hints--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
`multiplesOf3and5(10)` should return a number.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
assert(typeof multiplesOf3and5(10) === 'number');
|
|
|
|
```
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
`multiplesOf3and5(49)` should return 543.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
assert.strictEqual(multiplesOf3and5(49), 543);
|
2018-09-30 22:01:58 +00:00
|
|
|
```
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
`multiplesOf3and5(1000)` should return 233168.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
assert.strictEqual(multiplesOf3and5(1000), 233168);
|
|
|
|
```
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
`multiplesOf3and5(8456)` should return 16687353.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
|
|
|
```js
|
2020-11-27 18:02:05 +00:00
|
|
|
assert.strictEqual(multiplesOf3and5(8456), 16687353);
|
|
|
|
```
|
2020-09-15 16:57:40 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
`multiplesOf3and5(19564)` should return 89301183.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
assert.strictEqual(multiplesOf3and5(19564), 89301183);
|
2018-09-30 22:01:58 +00:00
|
|
|
```
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --seed--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
## --seed-contents--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
|
|
|
function multiplesOf3and5(number) {
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
multiplesOf3and5(1000);
|
|
|
|
```
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --solutions--
|
2018-09-30 22:01:58 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
const multiplesOf3and5 = (number) => {
|
|
|
|
var total = 0;
|
|
|
|
|
|
|
|
for(var i = 0; i < number; i++) {
|
|
|
|
if(i % 3 == 0 || i % 5 == 0) {
|
|
|
|
total += i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return total;
|
|
|
|
};
|
|
|
|
```
|