Home>Article>Web Front-end> How to add from 1 to 50 in javascript

How to add from 1 to 50 in javascript

WBOY
WBOY Original
2021-12-07 10:10:10 3856browse

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;}”.

How to add from 1 to 50 in javascript

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:

How to add from 1 to 50 in javascript

[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn