Skip to content

Commit

Permalink
sum-earnings by ikyli
Browse files Browse the repository at this point in the history
  • Loading branch information
kylifoo committed Oct 22, 2019
1 parent 6eb5472 commit 9559c21
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions javascript/beginner/sum-earnings_ikyli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function sumEarnings(numbers) {
var total = 0;
loop = 0;
console.log(numbers);
while (loop < numbers.length) {
if (total >= 0) {
total = total + numbers[loop];
console.log("sum is " + total);
loop += 1;
} else {
console.log("Starts from begining");
total = 0;
if (numbers[loop] != null) {
total = total + numbers[loop];
console.log("sum is " + total);
loop += 1;
}
}
}
}

var array = Array(3, 2, 10, 6, -17, -12, 20, 2);
sumEarnings(array);

0 comments on commit 9559c21

Please sign in to comment.