 # Trouble with Credit Card Checker Project

I’ve been working on step 3 of the credit card checker, and I am having an issue getting the values in my array to double as needed for the Luhn algorithm. As I have been unable to get any of the values to double, I currently working on getting all of them to double (and ignoring other aspects of the exercise at the moment). I recognize that this is not what step 3 is asking for, but I am trying to isolate whatever it is that I am doing incorrectly. Here’s the code:

``````const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8];

const validateCred = (arr) => {
let copyArr = arr;
for (let i = 0; i < copyArr.length; i++) {
let x = copyArr[i];
x = x * 2;
}
return copyArr;
};

console.log(valid1);
console.log(validateCred(valid1));

``````

The console.logs at the bottom are for me to compare what my function is doing relative to the initial array. I copied the initial array so as not to change it per the instructions on the exercise. From there, I created a “for loop” that I thought would double each value within the array. However, the values returned from the console.logs are exactly the same. I’m obviously doing something wrong, so any help would be appreciated; thanks!

you didn’t, PoC to make my point:

``````a = ['a', 'b', 'c']
b = a
b = 'd'
console.log(a);
``````

okay, now for the more important issue. Here:

``````let x = copyArr[i];
``````

you extract a copy of the value from the array. Which you then multiply:

``````x = x * 2;
``````

but then you never update the array?

Ok, thanks! I have changed the copying code to:

``````let copyArr = arr.slice();
``````

I guess the more important issue is the one that I don’t get. I don’t understand why the array isn’t itself updated by x = x * 2 due to the previous relationship between x and copyArr[i].

I know that I’m wrong and not thinking about the issue properly, so I’ve tried a number of methods from the MDN array page (here); but, I still can’t figure it out.

there isn’t a relation, like i stated in my answer:

the value you retrieve from the list is a copy, any changes made to it won’t affect the list.

The MDN page doesn’t contain what you need (did a quick scan), i would start googling how you update an element in an array.