-
Notifications
You must be signed in to change notification settings - Fork 0
/
euler.js
62 lines (56 loc) · 1.22 KB
/
euler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var changeIt = function() {
document.getElementById("content").innerHTML = "changed.";
};
var threesAndFives = function (limit) {
var sums = 0;
for (var i = 0; i < limit; i += 3) {
sums += i;
};
for (var j =0; j < limit; j += 5) {
if (j % 3 !== 0) {
sums += j;
};
};
document.getElementById("tf").innerHTML = sums;
};
var evenFibs = function (limit) {
var i = 0;
var j = 1;
var fib = i + j;
var sum = 0;
while (fib < limit) {
i = j;
j = fib;
fib = i + j;
if (fib % 2 === 0) {
sum += fib;
};
};
document.getElementById("evenFibs").innerHTML = sum;
};
var pm = function (limit) {
var multiples = [];
var square = Math.floor(Math.sqrt(limit));
console.log(square);
var isPrime = function (max) {
for (var i = 2; i < max; i++){
if (max % i === 0) {
return false;
};
};
return true;
};
var findMultiples = function (number) {
for (var j = 2; j < square; j++) {
if (number % j === 0) {
console.log("checking to see if " + j + " is a prime number");
if (isPrime(j)) {
multiples.push(j);
};
};
};
};
findMultiples(limit);
console.log(multiples);
document.getElementById("pm").innerHTML = multiples;
}