Javascript algorithm variable

Tell us what’s happening:
Describe your issue in detail here.
in the code the variable cent appears as if it had not been used, that is, it appears in the declaration let cent = 0 (with cent as unclear), this happens even when I use it inside the for (cent)

  **Your code so far**

function diffArray(arr1, arr2) {
let newArr = [];
let cent = 0;

for (let i=0;i<arr2.length;i++) {
  
  for (let j=0;j<arr1.length;j++) {
      if (arr2[i]===arr1[j]) {
        cent = 1;
      }
  }


}


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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36

Challenge: Diff Two Arrays

Link to the challenge:

OK, but from where does cent come? It’s not part of the starter code. You must have added it in.

Variables algorithms, Wow. I thinks you’re a beginner and you should put in somes time to REDACTED ARTICLE LINK fundamentals.

Based on your code, declaring a function that accept two arrays as an arguments. You’re doing it right by passing in exactly two set of arrays.
But what is wrong?

You have declared and empty array:

let newArr = [];

And you haven’t performed any operation on this array and you’re returning it in the function.

So guess what will happen even though you pass arguments to the function?

HI @justiceankomah !

I redacted the link for your javascript article.

Kudos for what you’re doing, but we don’t allow people to use the freeCodeCamp forum for promotional purposes. If you would like to be one of the developer authors for Free Code Camp News, you can find everything you need to know in the Publication Style Guide, or read here about how to contribute to freeCodeCamp’s YouTube channel. Alternatively, you can find everything else about contributing to Free Code Camp in the contributing docs.

1 Like

I will suppose that you don’t have problems solving the challenge and the only question you have is about the cent variable.

The editor shows the following text: 'cent' is declared but its value is never read.

As you can imagine that statement is correct, you have declared the variable, assigned some value but you have never readed the variable. Once you add something to read the variable the message disappear:

cent = 1;
console.log(cent);

I hope I was able to solve your question.