Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
function sumPrimes(num) {
var x=2;
var added=2;
while (x<num) {
x++;
for (var i=2;i<x;i++){
if (x%i===0){
break;
}
else if (i===x-1) {
added += x;
}
}
}
return added;
}
Indentation style - Wikipedia[
^]
Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[
^]
ultraedit[
^]
Enabling Open Innovation & Collaboration | The Eclipse Foundation[
^]
-----
As a beginner, you make a common mistake, you make monolithic code, everything is in a single function, the problem, it complicate writing and testing.
Look at this
function sumPrimes(num) {
var added=0;
for (var i=2; i<num; i++){
if (IsPrime(i)){
added += i;
}
}
return added;
}
function IsPrime(num) {
for (var i=2; i<num; i++){
if (num%i===0){
return false;
}
}
return true;
}