Credit Card Checker Project

Hi.

I’m currently attempting the Credit card checker project but have run into a problem.

https://www.codecademy.com/practice/projects/credit-card-checker

I’m part way through step 3 where I have to double every second digit. I’m trying to check that my code is ok with a console.log but with the methods I have tried I get either ‘undefined’ or ‘RangeError’ messages. I have spent a lot of time trying to figure out where I have gone wrong to no avail so I’m hoping someone here can point me in the right direction.

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

function validateCred(numArr) {
const cardCopy = numArr;
//const arr = ;
let card = cardCopy.slice(0, -1).reverse();
//console.log(cardCopy);
//console.log(card);
for (let i = 0; i < card.length; i += 2) {
card[i] *= 2;
//console.log(validateCred(valid1))
}
};
//validateCred(valid1);
//console.log(validateCred(valid1))

What specific operation makes an error message show up? What input did you feed to that operation? Is the input correct? Was operation used correctly with the input?

Jeez im really struggling with this one.

I have gone over the previous code and found where I made a lot of my mistakes. I decided to go back and start a similar yet easier task and had good progress getting the results I want, see below.

This gets the job done but is logging three sets of arrays.
I believe its because of the console.log at the the end of the for loop but if I remove it I get no log at all.
Each function call gives me three logs and the last one is the correct result.
How can I change my code to print only the final result while still getting a console.log to check my results?. I also discovered the more elements I add to the array the more console.logs I get.

I appreciate you taking the time to help a noob out.

If you mean to do something once then it probably shouldn’t be in a loop right?


let arr2 = arr

Seems redundant to have two variables refer to the same array if you ask me.