Tell us what’s happening:
Unless I am completely misunderstanding this simple premise… all of the tests answers, except for the first test, are wrong. I can’t even begin to understand how they got what they are calling the correct answers. Can someone please break this down Barney style for me, so I can try and complete this challenge. Thank you!
Your code so far
function sumOfDifferences(arr) {
let diff;
let total = 0;
for (let i = 0; i < arr.length; i++) {
if (i === arr.length - 1) {
continue;
}
if (arr[i] > arr[i + 1]) {
diff = arr[i] - arr[i + 1];
} else {
diff = arr[i + 1] - arr[i];
}
total += diff;
}
return total;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36
Challenge Information:
Daily Coding Challenge - Sum of Differences
https://www.freecodecamp.org/learn/daily-coding-challenge/2026-05-26