Thanh Thảo
New member
What will be the output of the following JavaScript code if oddsums(5); is executed after the following code snippet?
A. Returns [1,4,9,16,25]
B. Returns [1,2,3,4,5]
C. Returns [3,6,9,12,15]
D. Returns [1,3,5,7,9]
Code:
function oddsums(n)
{
let total = 0, result=[];
for(let x = 1; x <= n; x++)
{
let odd = 2*x-1;
total += odd;
result.push(total);
}
return result;
}
B. Returns [1,2,3,4,5]
C. Returns [3,6,9,12,15]
D. Returns [1,3,5,7,9]