I have read the instructions multiple times for the project I have no clue how it ties into what we have been taught in the JavaScript course up to this point. Even other people I have seen working it out on YouTube are apparently people who already know programming and have used stuff that we haven’t been taught. I’m completely lost and completely stuck.

Could you post a link to the topic, please?

At which step are you stuck?

I’m stuck at step 3.

I don’t know what solutions can be found on Youtube, I’m sure there are plenty of different solutions of different levels. But this function can be written with a for loop and if/else statements. If I remember correctly, that was already part of the preceding lessons.Did you understand the Luhn algorithm?

Not at all. I read the documentation they gave and a few people explaining it on YouTube, but yet to have seen anything about implementation in this scenario.

But do you understand what the Luhn algorithm is supposed to do? Not how to implement it…

I honestly don’t understand either.

Let’s take this card:

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

You should double every other (every second → that’s where I was stuck as a non native english speaker) and subtract 9 if the product is larger than 10 while omitting the very last one.

From the end:

```
8 // leave that untouched
0 // double --> 0
8
6 // double and subtract 9 --> 12 - 9 --> 3
1
0 // double --> 0
8
0 // double --> 0
9
7 // double and subtract 9 --> 14 - 9 --> 5
7
6 // double and subtract 9 --> 12 - 9 --> 3
9
3 // double --> 6
5
4 // double --> 8
```

So the above array should become:

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

Then you sum up each number of the result array:

8+5+6+9+3+7+5+9+0+8+0+1+3+8+0+8 = 80

If you divide the result by 10 and the result is an absolute number with no decimals it is a valid number and your function should return true.

```
80 % 10 = 0 // no rest value --> true
80 / 10 = 8 // absolute number --> true
```

Ok, but what am I supposed to do with this? I’m still completely lost.

I know what you mean sometimes I get so frustrated but it keep going

and then after awhile it works!

I can’t even start. I literally do not understand what it is asking of me.

oh what programming language is this??

The code language is JavaScript.

cuz i don’t have pro

ok so what kind of error?

Bro, I recently completed this problem, I can help you. I had this problem before when I was taking Introduction to Computer Science in a different platform and completed it on C, then had to make an adaptation on Python, and now in Codecademy had to do it again with JavaScript.

The whole point of the problem is to verify if a credit card number is valid or not. All credit card numbers have to follow certain rules such as: the luhn algo, the first two numbers of the credit card and the number of digits on the credit card. You can detect fake credit cards by looking at these factors to speed the authentication process.

Notable Methods you can use to solve this problem are, .slice(), .reduce(); you also going to need loops. Divide the problem into simpler steps and tackle each problem as a sub-problem.

Does that mean you understand the Luhn algo now? Because that would be one step further from what you wrote before…

A common and simple approach would be this:

- Write a function (leave the body empty for now) that has a parameter for the card array
- In the function body copy the array in order to leave the input array unaltered (e.g. slice() method as mentioned in another post or spread syntax)
- Reverse the copied array in order to iterate from end to start (reverse() method)
- Write a new variable and assign it to an empty array
- Write a for loop that iterates over each digit in the copied and reversed array
- Inside the for loop, find out which index is odd (because that omits the check digit)
- If the index is odd, double the digit (if statement)
- If the result is larger than 10, subtract 9 (same, if statement)
- Push the result to the new array – also the unaltered digits from the even indexes of the for loop
- Sum up each digit from the new array (reduce() method or another loop)
- Find out if there is a rest if you divide the sum by 10 (modulo operator)
- Return true from the function is there is no rest value

Review the lessons if anything is unfamiliar to you, all of the above has been taught in the lessons.

thank you so much omg. As a non-native speaker it’s pretty hard to understand what they wanted me to do

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