• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Make an addition! …

LEGEND ,
Dec 18, 2016 Dec 18, 2016

Copy link to clipboard

Copied

Hi Scripters,

I'm surely tired!

I'm writing a script based on a loop that gives me a number at each step:

step 1: 24.215

step 2: 10.784

step 3: 72.581

step n: 35.822

I just want to total all the numbers!

… and, truly, no idea! 

Thanks in advance!

(^/)

TOPICS
Scripting

Views

284

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Dec 18, 2016 Dec 18, 2016

var i = 0, n = 5, sum = 0;

while ( i<n ) {

     sum+=(i+1);

     i++;

}

alert( sum);

Votes

Translate

Translate
People's Champ ,
Dec 18, 2016 Dec 18, 2016

Copy link to clipboard

Copied

var i = 0, n = 5, sum = 0;

while ( i<n ) {

     sum+=(i+1);

     i++;

}

alert( sum);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2016 Dec 18, 2016

Copy link to clipboard

Copied

LATEST

Loic,

Thanks a lot!

I've just added:

    sum += myStepNumber;

in the loop.

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines