Credit Card Checker

Hi all,

I am working on the credit card checker project: https://www.codecademy.com/practice/projects/credit-card-checker

I have managed to get the result needed for step 3, validateCred()

My question is, at the bottom of the function, when I call the function and pass int he argument, nothing gets printed to the console. I have to wrap console.log around the call. Why does the code not print 0 (the expected result) to the console without console.log?

I know I have a lot of refactoring to do but I at least got to the expected result, next steps are to refactor. Code below:

const validateCred = (arr) => {
  arr.pop()
  arr.reverse();
  let newArr = []
  for (let i = 0; i < arr.length; i++) {
   if (i % 2 === 0 ) {
     arr[i] = arr[i] * 2;
     if (arr[i] > 10) {
       arr[i] = arr[i] - 9;
     }
   }
    newArr.push(arr[i]); 
  }
  
  let value = 0;
  for (let i =0; i < newArr.length; i++) {
    value += newArr[i];
  }
  
  let finalArr = value + 8 
  finalArr = finalArr % 10
  if (finalArr === 0) {
    return true;
  } else {
    return false;
  }
};



console.log(validateCred(valid1)); //Works
validateCred(valid1);  //Does not print true, print nothing```

Well the reason it is not logging anything is because you are not telling it to do so :stuck_out_tongue:

1 Like

Why are you expecting to print to the console without console.log()? Also you are mutating the original array with reverse(), you want to make a copy first than you can use reverse()

2 Likes

If you want the validateCred function to log anything you have to include it inside the function using console.log.

You could modify the last part of your function like so:

let verdict 
if (finalArr === 0) {
    verdict = true;
} else {
    verdict = false;
}
console.log(verdict); // this prints in the console
return verdict; // returns the value of verdict, you will need this in the next part of the assignment
1 Like

Thank you for the time and help!