2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
id: 5900f36e1000cf542c50fe80
|
|
|
|
challengeType: 5
|
2020-05-21 17:31:25 +02:00
|
|
|
isHidden: false
|
2018-09-30 23:01:58 +01:00
|
|
|
title: 'Problem 1: Multiples of 3 and 5'
|
2019-08-05 09:17:33 -07:00
|
|
|
forumTopicId: 301722
|
2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
|
|
|
<section id='description'>
|
2020-02-28 21:39:47 +09:00
|
|
|
|
2018-09-30 23:01:58 +01: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 21:39:47 +09:00
|
|
|
|
|
|
|
Find the sum of all the multiples of 3 or 5 below the provided parameter value `number`.
|
|
|
|
|
2018-09-30 23:01:58 +01:00
|
|
|
</section>
|
|
|
|
|
|
|
|
## Instructions
|
|
|
|
<section id='instructions'>
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
2018-10-04 14:37:37 +01:00
|
|
|
tests:
|
2020-02-28 21:39:47 +09:00
|
|
|
- text: <code>multiplesOf3and5(10)</code> should return a number.
|
|
|
|
testString: assert(typeof multiplesOf3and5(10) === 'number');
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: <code>multiplesOf3and5(49)</code> should return 543.
|
2019-07-25 08:44:15 -07:00
|
|
|
testString: assert.strictEqual(multiplesOf3and5(49), 543);
|
2020-02-28 21:39:47 +09:00
|
|
|
- text: <code>multiplesOf3and5(1000)</code> should return 233168.
|
|
|
|
testString: assert.strictEqual(multiplesOf3and5(1000), 233168);
|
2019-11-20 07:01:31 -08:00
|
|
|
- text: <code>multiplesOf3and5(8456)</code> should return 16687353.
|
2019-07-25 08:44:15 -07:00
|
|
|
testString: assert.strictEqual(multiplesOf3and5(8456), 16687353);
|
2020-02-28 21:39:47 +09:00
|
|
|
- text: <code>multiplesOf3and5(19564)</code> should return 89301183.
|
|
|
|
testString: assert.strictEqual(multiplesOf3and5(19564), 89301183);
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
function multiplesOf3and5(number) {
|
|
|
|
// Good luck!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
multiplesOf3and5(1000);
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
|
|
|
|
```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;
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|