Skip to content

Commit 90891b5

Browse files
authored
Fix Euler Problem 1 (#467)
* refactor code to ES6 styling, fixed incorrect code and broken input in Problem 1 * standard styling * use standard * removed changes to Problem 2 * added URL to euler problem
1 parent cedab19 commit 90891b5

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Project-Euler/Problem1.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1+
// https://projecteuler.net/problem=1
12
/* Multiples of 3 and 5
23
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.
34
Find the sum of all the multiples of 3 or 5 below the provided parameter value number.
45
*/
56

6-
function multiplesThreeAndFive (num) {
7+
const readline = require('readline')
8+
9+
const multiplesThreeAndFive = (num) => {
710
let total = 0
811
// total for calculating the sum
9-
for (let i = 0; i <= num; i++) {
12+
for (let i = 0; i < num; i++) {
1013
if (i % 3 === 0 || i % 5 === 0) {
1114
total += i
1215
}
1316
}
1417
return total
1518
}
1619

17-
var num = console.log('Enter a number: ')
18-
console.log(multiplesThreeAndFive(num)) // multiples3_5 function to calculate the sum of multiples of 3 and 5 within num
20+
const rl = readline.createInterface({
21+
input: process.stdin,
22+
output: process.stdout
23+
})
24+
rl.question('Enter a number: ', function (num) {
25+
console.log(multiplesThreeAndFive(num)) // multiples3_5 function to calculate the sum of multiples of 3 and 5 within num
26+
rl.close()
27+
})

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)