simple project meet all the requirements (list, function)

來源: 2025-03-07 18:46:25 [舊帖] [給我悄悄話] 本文已被閱讀:

Make sure your program includes a function that has
a parameter, an if-statement, and a loop.

Example Algorithm 4

function addPositives(list){

  var total = 0;

  var currentItem;

  for(var i = 0; i < list.length; i++){

    currentItem = list[i];

    if(currentItem > 0){

      total = total + list[i];

    }

  }

  return total;

}