Hello coders!
I am trying to solve challenge with Prime Numbers" Intermediate Algorithm Scripting: Sum All Primes".
my code is:
function sumPrimes (num){
var arrOfNum = createArrOfNum(num);
var arrOfPrimes = [];
for (var i = 0; i < arrOfNum.length; i++){
var numToTest = arrOfNum[i];
arrOfPrimes.push(isAprimeNum(numToTest));
}
var sumP = sum(arrOfPrimes);
var num = sumP - 1; // while 1 is not a Prime Number
return (num);
}
function createArrOfNum (num){
var arrOfNum = [];
for (var i = 1; i <= num; i++){
arrOfNum.push(i);
}
return arrOfNum;
}
function isAprimeNum(num){
var arrOfTestNum = createArrOfTestNum(num);
var flag = true;
for (var k = 0; k < arrOfTestNum.length; k++) {
var remainder = num % arrOfTestNum[k];
if (remainder == 0){
flag = false;
}
}
if (flag == true){
return num;
}else{
return 0;
}
}
function createArrOfTestNum (num){
var arrOfTestNum = [];
var lastTestNum = num - 1;
for (var j = 2; j <= lastTestNum; j++){
arrOfTestNum.push(j);
}
return arrOfTestNum;
}
function sum (arrOfPrimes){
var sum = 0;
for (var j = 0; j < arrOfPrimes.length; j++){
sum += arrOfPrimes[j];
}
return sum;
}
I wrote the code at js.do . When I tested it at js.do, everything was ok.
When I tested it at freeCodeCamp with the number 977 the test failed.
Where is my mistake?
Is it problem of new FCC platform?
Honestly these updates are not user-friendly.
I am looking for prompt help.
sincerely yours,
Maria