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!
https://www.codecademy.com/practice/projects/credit-card-checker