Skip to content

Commit 8de2d88

Browse files
problem 33 solved
1 parent d9653a3 commit 8de2d88

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

problem33/problem.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Write a function findOddSum() that will take the array [5, 7, 8, 10, 45, 30]
2+
as the input parameter and will return the sum of the odd numbers.

problem33/problem33.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Write a function findOddSum() that will take the array [5, 7, 8, 10, 45, 30]
2+
as the input parameter and will return the sum of the odd numbers. */
3+
4+
5+
6+
function findOddSum(numbers){
7+
8+
let sum = 0;
9+
for(let i = 0; i < numbers.length; i++){
10+
11+
const index = i;
12+
const number = numbers[i];
13+
14+
if(number % 2 === 1){
15+
sum = sum + number;
16+
}
17+
18+
}
19+
return sum;
20+
}
21+
22+
23+
const givenNumbers = [5, 7, 8, 10, 45, 30] ;
24+
25+
const sumOfAllOdds = findOddSum(givenNumbers);
26+
console.log("Total of all Odd number is",sumOfAllOdds);

0 commit comments

Comments
 (0)