-
Notifications
You must be signed in to change notification settings - Fork 105
Ejercicio de Tarjeta de credito #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .eslintrc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1 @@ | ||
| # Tarjeta de crédito válida | ||
|
|
||
| Crea una web que pida, por medio de un `prompt()`, el número de una tarjeta de | ||
| crédito y confirme su validez según el [algoritmo de Luhn](https://es.wikipedia.org/wiki/Algoritmo_de_Luhn). | ||
| Lee este blog que explica [cómo funciona el algoritmo de Luhn](http://www.quobit.mx/asi-funciona-el-algoritmo-de-luhn-para-generar-numeros-de-tarjetas-de-credito.html). | ||
|
|
||
| ## Entregables | ||
|
|
||
| Para cada producto debes entregar **un repositorio de GitHub** que | ||
| contenga: | ||
| 1. Archivo `README.md` que explique el **pseudocódigo** de tu solución y su | ||
| **diagrama de flujo** | ||
| 2. Archivo `app.js` con el **código** de tu solución | ||
| 3. Archivo `index.html` vinculado con tu `app.js` | ||
|
|
||
| ## Tips | ||
|
|
||
| A continuación un video de Michelle que te lleva a través del algoritmo de | ||
| Luhn y te da tips para completar este proyecto: | ||
|
|
||
| [](https://www.youtube.com/watch?v=f0zL6Ot9y_w) | ||
|
|
||
| ## Consideraciones específicas | ||
|
|
||
| 1. Tu código debe estar compuesto por 1 función: `isValidCard` | ||
| 2. El usuario no debe poder ingresar un campo vacío | ||
|
|
||
| ## Criterios de evaluación | ||
|
|
||
| Se tomarán en cuenta las siguientes consideraciones a la hora de evaluar tu solución: | ||
|
|
||
| 1. Nombramiento de variables | ||
| 2. Indentación | ||
| 3. Validación de input: el usuario no debe poder ingresar un campo vacío o de tipo que no corresponda | ||
| 4. Estructura de tus archivos | ||
| 5. Archivo `README.md` correctamente redactado | ||
| 6. Uso de comentarios para hacer tu código más legible | ||
| 7. Que el programa cumpla con el propósito requerido |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| var cardNumber = prompt('INGRESE SU NUMERO DE TARJETA'); // creammos la variable donde se almacena el numero de la tarjeta | ||
| var array = []; // pasar los elementos de la tarjeta a un array | ||
| for (i = 0; i < cardNumber.length; i++) { | ||
| array.push(cardNumber[i]); | ||
| } | ||
|
|
||
| for (j = 0; j < array.length; j++) {// invertir los elementos del array | ||
| var item = array.pop(); | ||
| array.splice(j, 0, item); | ||
| } | ||
| var newArray = []; // variable donde se almacenara los numeros | ||
| for (k = 0; k < array.length; k++) { | ||
| newArray.push(parseInt(array[k])); | ||
| } | ||
| var newArray = []; // variable donde se almacenara los numeros de uno en uno //4088521938925895 | ||
| for (k = 0; k < array.length; k++) { | ||
| newArray.push(parseInt(array[k])); // newArray[5, 9, 8, 5, 2, 9, 8, 3, 9, 1, 2, 5, 8, 8, 0, 4] | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No hace falta crear newArray dos veces (?) |
||
| // separando numeros pares de impares | ||
| var pair = []; // numeros pares | ||
| var impair = 0; // numeros impares // 47 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. se dice "even" (par) y "odd" (impar) |
||
| for (m = 0; m < newArray.length; m++) { | ||
| if ([m + 1] % 2 === '0') { | ||
| pair.push((newArray[m]) * 2); | ||
| } else if ([m + 1] % 2 !== 0) { | ||
| impair += newArray[m]; | ||
| } | ||
| } | ||
| // separando los numeros pares = o mayores que 10 | ||
| var smallNumbers = 0; // numeros menores que 10 | ||
| var bigNumbers = []; // numeros mayores que 10 | ||
| for (p = 0; p < pair.length; p++) { | ||
| if (pair[p] <= 10) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. < 10 |
||
| smallNumbers += (pair[p]); | ||
| } else { | ||
| bigNumbers.push(pair[p]); // [ 10, 18 ] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tal vez seria mas facil sumar los bigNumbers aqui. Es util notar que un numero como 13 se puede separar restando 10. |
||
| } | ||
| } | ||
|
|
||
| var joinedNumbers = bigNumbers.join(''); // 1018 | ||
| var numberSeparated = joinedNumbers.split(''); // [ '1', '0', '1', '8' ] | ||
|
|
||
| var arrayNumbers = []; | ||
| for (q = 0; q < numberSeparated.length; q++) { // pasando numeros para sumarlos // [ 1, 0, 1, 8 ] | ||
| arrayNumbers.push(parseInt(numberSeparated[q])); | ||
| } | ||
|
|
||
| var sumOfLarge = 0; | ||
| for (r = 0; r < arrayNumbers.length; r++) { | ||
| sumOfLarge += (arrayNumbers[r]); | ||
| } | ||
|
|
||
| var count = impair + smallNumbers + sumOfLarge; | ||
| if (cardNumber === '' || cardNumber !== Number) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "cardNumber !== Number" no sirve para verificar que el string solo contiene digitos. Podrias hacer on for loop y verificar que cada character es un digito. |
||
| alert('TIENE QUE INGRESAR NUMERO VALIDO '); | ||
| } else if (count % 10 === 0) { | ||
| alert('TU TARJETA DE CREDITO ES VALIDA '); | ||
| } else { | ||
| alert('TU TARJETA DE CREDITO ES INVALIDA'); | ||
| } | ||
|
|
||
| // 4088521938925895 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title></title> | ||
| </head> | ||
| <body> | ||
| <script type= tarjeta de credito/javascript" src="app.js"> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type="text/javascript" ? |
||
|
|
||
| </script> | ||
| </body> | ||
| </html> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
las listas y arrays tienen un método 'reverse'