0

Create a function that will be return of the sum of even numbers from 4 o 401. Help.

Attempt: function sum_even() { var sum = 0; for ( var i = 4; i < 387; i++) { if (i % 2==0) { sum +=i; } } return sum; }

11th Feb 2020, 12:47 AM
Tsering Kalden
Tsering Kalden - avatar
8 Respostas
+ 1
Your i is sometimes lower, sometimes upper. Otherwise looks like it should work actually. 🤔 What exactly goes wrong?
11th Feb 2020, 1:03 AM
HonFu
HonFu - avatar
+ 1
Do you call it?
11th Feb 2020, 1:07 AM
HonFu
HonFu - avatar
+ 1
A function is a sub-code that only runs if you call it. Write this under your function: console.log(sum_even()); (First tidy up the syntax though. For also can't start with capital.)
11th Feb 2020, 1:10 AM
HonFu
HonFu - avatar
0
It's not 387..its 401
11th Feb 2020, 12:54 AM
Tsering Kalden
Tsering Kalden - avatar
0
When I run it am getting blank on my console.
11th Feb 2020, 1:06 AM
Tsering Kalden
Tsering Kalden - avatar
0
What do you mean by call?
11th Feb 2020, 1:08 AM
Tsering Kalden
Tsering Kalden - avatar
0
just after the function
11th Feb 2020, 1:21 AM
Tsering Kalden
Tsering Kalden - avatar
0
Yeah.
11th Feb 2020, 1:21 AM
HonFu
HonFu - avatar