Tell us what’s happening:
I can’t understand why my code works in Chrome and in the Eloquent Javascript sandbox but not here. Could someone explain it, please?
Your code so far
function diffArray(arr1, arr2) {
var newArr = [];
for (i of arr1){
if (!arr2.includes(i)){
newArr.push(i)
}
}
for (j of arr2){
if (!arr1.includes(j)){
newArr.push(j)
}
}
return newArr;
}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36.
If you look at the error it will say:
“Can’t find variable: i”
You have not declared your variables i and j.
I haven’t used
But a quick look says there is other background code added. I don’t think they would fix undeclared variables, but maybe the variables were already declared in some boilerplate code.
I’m not sure what you mean by your code works in Chrome
Chrome is a web browser, and I suspect you are using Chrome to access freeCodeCamp?
Yes you have to use let or var or const to declare your variable. Perhaps in the other places you were writing code it was declared outside your function. But either way it still needs to be declared.