Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.eslintrc
37 changes: 0 additions & 37 deletions README.md
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:

[![tips credit card](https://img.youtube.com/vi/f0zL6Ot9y_w/0.jpg)](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
62 changes: 62 additions & 0 deletions app.js
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);
}
Copy link

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'

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]
}
Copy link

Choose a reason for hiding this comment

The 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
Copy link

Choose a reason for hiding this comment

The 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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

< 10

smallNumbers += (pair[p]);
} else {
bigNumbers.push(pair[p]); // [ 10, 18 ]
Copy link

Choose a reason for hiding this comment

The 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.
13 - 10 = 3 (el digito menor)
1 + 3 = 4 (suma de los digitos)

}
}

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) {
Copy link

Choose a reason for hiding this comment

The 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
12 changes: 12 additions & 0 deletions index.html
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">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type="text/javascript" ?


</script>
</body>
</html>