Credit Card Checker, put elements back in array

This is probably an easy solution, but I really can’t think of what I’ve done wrong. I think my structure might be wrong.

Full JavaScript file here

When I try to do this (code below) I get the wrong output.

let array = [];
array.push(newNum);
console.log(array);

Output:
[ 0 ]
[ 3 ]
[ 0 ]
[ 0 ]
[ 5 ]
[ 3 ]
[ 6 ]
[ 8 ]

I’m trying to get [0, 3, 0, 0, 5, 3, 6, 8]

I’ve tried several things but have been stuck here for a while.

Original array (I’m using array valid1):
[4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8].
This should lose it’s last element (pop), iterate in reverse, every second number should be multiplied by two, if this higher than 9, substract 9 and get the sum of all numbers combined.

However because I don’t know how to put every element in one array instead of all different elements, I’m not sure how I can get the sum of these elements.

I’m happy to hear any suggestions on how I can improve the code to get further through this project!

Hello @sarahvandenberghe.

Welcome to the forums.

Consider what happens to array every time let array = [] executes. How often does it execute?

Link to project for reference: https://www.codecademy.com/practice/projects/credit-card-checker

1 Like

Oh wow, and to think I’ve been staring at it for so long without a clue. I put my let array outside of the block code now and I got the result I want. Thank you so much! :slightly_smiling_face:

1 Like

Your welcome! Happy to help.

1 Like

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.