Current location - Training Enrollment Network - Mathematics courses - Find a javascript scripting language to find the sum of all even numbers between 1 and 100?
Find a javascript scripting language to find the sum of all even numbers between 1 and 100?
& lt script & gt

var? sum? =? 0; ? //Define a sum variable with an initial value of 0 as an accumulator.

for(var? Me? =? 2; Me? & lt=? 100; i+=2){?

/*

Define a variable I to store the current even number; When I is less than or equal to 100, execute the following accumulation statement.

; After the accumulation statement is executed, the I variable will be increased by 2, and judgment-accumulation will continue.

*/

sum? +=? Me; ? //Add the value of I to the sum.

}

Console.log(sum)// Finally, output the summation result on the console, 2550.

& lt script & gt