<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Below this line, add a link to the EXACT exercise that you are stuck at.>
Using the basic function given below, add code so that sum_odd_numbers will print to the console the sum of all the odd numbers from 1 to 3000. Don’t forget to call the function!
<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
I am getting the sum and then under it undefined. So
40677 //random numbers
undefined
How can I do this correctly and get rid of the undefined? Also the question is asking me to put var sum= 0 inside the function brackets but is that possible? I have it on top because that’s the only way I can get it to work.
var sum = 0;
function sum_odd_numbers() {
for (var i = 1; i < 3000; i += 2) sum += i;
console.log(sum);
}
console.log(sum_odd_numbers(sum));