Learn Advanced Array Methods by Building a Statistics Calculator - Step 53

Tell us what’s happening:

hello team, i am stuck here. i dont know what is wrong with my code. instruction was pretty clear, just that i dont know which part is wrong. have tried multiple ways of solution but none is helping.

can help to clarify to me which part i did wrong?

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

const getVariance = (array) => {
  const mean = getMean(array);
  const sumSquaredDifferences = array.reduce((acc, el) => {
    const difference = el - mean;
    const squared = difference ** 2;
    return acc + squared;
  }, 0 / array.length);
  return variance;
};


// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Learn Advanced Array Methods by Building a Statistics Calculator - Step 53

where is variance defined? I am not seeing it, so I guess you have a syntax error

why did you change the name of the variable in the variable initialization?

@ILM

  1. i forgot to declare the variance, so here’s my updated code:
const getVariance = (array) => {
  const mean = getMean(array);
  const sumSquaredDifferences = array.reduce((acc, el) => {
    const difference = el - mean;
    const squared = difference ** 2;
    return acc + squared;
  }, 0);
  const variance = sumSquaredDifferences / array.length;
  return variance;
};
  1. could you highlight which part did i change? dont think i change anything, i followed based on the last exercise.

i tried to look at other tutorials, however i’m still not getting pass this. please bear with me T_T

Hi there!

You aren’t need the above declaration. The instructions is asking only for: Divide your .reduce() call by the length of the array (in your variance declaration). Then, return variance.

Hint: you need to begun the new line of code after the closing round brace of your reduce method.

it still flagged me the same error :frowning:

error message: You should divide the result of the .reduce() call by the length of the array.

const getVariance = (array) => {
  const mean = getMean(array);
  const sumSquaredDifferences = array.reduce((acc, el) => {
    const difference = el - mean;
    const squared = difference ** 2;
    return acc + squared;
  }, 0) / array.length;
  return variance;
};

I tried to copy and paste the above code to the challenge step and it’s passing from my end. Reset the challenge step and try again.

Hi @shuhadahzon

Try renaming …

to variance.

That way variance is defined.

Happy coding

OMG FINALLY I PASSED!! i deleted the code and re-type again and it worked!!

thank you everyone for helping :)))

1 Like