Daily Coding Challenge - Pairwise

Tell us what’s happening:

I’m not sure why this isn’t working. I put the same code in vscode and it returns the right values. How come its not working here. Is there syntax missing or is my logic wrong.

Your code so far

function pairwise(arr, target) {
	const pairs = [];
	if (arr.length == 0) {
		return arr;
	}
	for (i = 0; i < arr.length; i++) {
		for (j = i + 1; j < arr.length; j++) {
			if (arr[i] + arr[j] == target) {
				pairs.push(i, j);
			}
		}
	};

	let sum = pairs.reduce((acc, curr) => {
		return acc + curr;
	}, 0);
	return sum;
}

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36

Challenge Information:

Daily Coding Challenge - Pairwise
https://www.freecodecamp.org/learn/daily-coding-challenge/2025-12-19

If you try to use the function, ie. by adding console.log(pairwise([2, 3, 4, 6, 8], 10)); below your code, there’s an error displayed:

ReferenceError: i is not defined

So why would you think it isn’t defined?

Because you didn’t define the variable!

(Recall, every variable should have let or const next to it when introduced!)

Oh duh. It was right in front of my face! :joy: Thank you guys. I guess i was trying to write in python.

1 Like