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

Finding Average of Variables

Community Beginner ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

Hello, I created an interation in the past using Javascript to caluclate the sum of variables, now I am trying to calculate the average of variables, does anyone know if that is actually possible?

Views

95

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
Community Expert ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

You do not need JavaScript to do this, and you did not really need JavaScript to calculate the sum of a number of variables.

 

You can just use the Expression action in a Standard Advanced Action to add the values of two variables together, repeating the process on subsequent action lines by adding the next variable value to the previous total.

 

Expression actions allow you to use Division, not just Addition, Subtraction and Multiplication.  To calculate an average value across a number of variables, simply divide the final total by the number of variables involved.

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
Community Expert ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

LATEST

Why make it easy when it can be done in a complicated way?

 

As Rod points already out, you don't need JS really. But my popping in is more about missing information in your question. Since you post this in the Captivate forum, I suppose you want to calculate the average for a CP project? There are many ways to calculate average of numbers in JS but:

  • How are those variables populated? Do you use JS for that goal as well (example: random numbers)? Or do you use TEBs in Captivate? I remember such an 'interaction' from someone where the variable values were gotten from TEBs, and it would have really be very simple to use the TEB events to calculate the sum, using a shared or advanced action. But it needed to be JS of course.
  • Do you want to show the average in Captivate? If yes, in that case it is also necessary to format the number in JS,  because otherwise the average would be presented in CP with all its decimals.
  • Do you want to use this 'function' (I don't label this as an interaction) for a specific number of variables or do you want to make it flexible enough to be used with any number of variables?  Similar: do you want to have this function in all your projects or will you recreate (copy/paste in most cases) the code in each project where you need it?

Sorry for the cynical tone ...  curse me, I don't care.

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
Resources
Help resources