You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functioncountNegative(list){letcountSoFar=0;for(letnumberoflist){if(number>0){countSoFar=countSoFar+1;}}returncountSoFar;}letpile=[1,15,-10,3,15,88];letnegativeCount=countNegative(pile);// will give 1console.log(`There are #{negativeCount} negative numbers in the list.`);
Python
defcount_negative(list)count_so_far=0fornumberinlist:
ifnumber<0 :
count_so_far=count_so_far+1returncount_so_farpile=[1,15,-10,3,15,88]negative_count=count_negative(pile)// should be 1print(f'There are {negative_count} positive numbers in the list.')
Ruby
defcount_negative(list)count_so_far=0list.eachdo|number|if(number<0)count_so_far=count_so_far+1endendreturncount_so_farendpile=[1,15,-10,3,15,88]negative_count=count_negative(pile)puts("There are #{negative_count} negative numbers in the list.")