Getting the sum of an array

can someone really tell what is wrong with my code ;

function getSum(n){
  //convert interger to string and split;
  const myArray = []
  let string  = n.toString().split("")

 mySum = myArray.reduce((prev, curr) => prev + curr, 0)

Was there any error message when you run this code?

If yes, please paste it here for context.

no error message , it just return on myconsole, the value in the array and added sum of 0…
just like this /// 01,234 ///

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.