Home>Article>Web Front-end> How to add from 1 to 50 in javascript
In JavaScript, you can use the for loop statement to implement the function of adding from 1 to 50. The for loop can loop and execute the specified code block under specified conditions. The syntax is "for(var i=1;i< ;=50;i ){sum =i;}”.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
How to add 1 to 50 in javascript
In JavaScript, you can use a for loop to add 1 to 50 and then output the result . The specific syntax is as follows:
for(var i=1;i<=50;i++){sum+=i;}
The example is as follows:
Document
Output result:
[Related recommendations:javascript learning tutorial】
The above is the detailed content of How to add from 1 to 50 in javascript. For more information, please follow other related articles on the PHP Chinese website!