Skip to content

Commit

Permalink
Fin sección 4
Browse files Browse the repository at this point in the history
  • Loading branch information
alesyt0h committed Sep 13, 2021
1 parent 470ba92 commit 2a1ec27
Show file tree
Hide file tree
Showing 18 changed files with 320 additions and 2 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
61 changes: 61 additions & 0 deletions assets/js/bases/if-else.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
let a = 10;

if (a >= 10) { // undefined, null, una asignación
console.log('A es mayor o igual a 10');
} else {
console.log('A es menor a 10');
}
// console.log('Fin de programa')


const hoy = new Date();
let dia = hoy.getDay(); // 0: Domingo, 1: lunes, 2: martes ....

console.log({dia});

if (dia === 0){
console.log('Hoy es domingo');
} else if (dia === 1) {

console.log('Lunes');

// if (dia ===1){
// console.log('Lunes')
// } else {
// console.log('No es lunes ni domingo')
// }

} else if (dia === 2) {
console.log('Martes');
} else {
console.log('No es lunes, martes o domingo...');
}

// Sin usar If Else, o Switch, únicamente objetos
// dia = 3; // 0: domingo

const dias = {
0: 'Domingo',
1: 'Lunes',
2: 'Martes',
3: 'Miércoles',
4: 'Jueves',
5: 'Viernes',
6: 'Sábado',
}

const diasConProcedimientos = {
0: () => 'Domingo - 0',
1: () => 'Lunes - 1',
2: () => 'Martes - 2',
3: () => 'Miércoles - 3',
4: () => 'Jueves - 4',
5: () => 'Viernes - 5',
6: () => 'Sábado - 6',
}

const diasConArray = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'];

console.log(dias[dia] || 'Día no definido');
console.log(diasConProcedimientos[dia]() || 'Día no definido');
console.log(diasConArray[dia] || 'Día no definido');
62 changes: 62 additions & 0 deletions assets/js/bases/logica-booleana.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const regresaTrue = () => {
console.log('Regresa true');
return true;
}

const regresaFalse = () => {
console.log('Regresa false');
return false;
}

console.warn('Not o la negación');
console.log(true); // true
console.log(!true); // false
console.log(false); // false
console.log(!false); // true

console.log(!regresaFalse()); // true

console.warn('And'); // true si todos los valores son verdaderos
console.log(true && true); // true
console.log(true && !false); // true


console.log('================');

console.log(regresaFalse() && regresaTrue()); // false
console.log(regresaTrue() && regresaFalse()); // false


console.log('=======&&=======');
regresaFalse() && regresaTrue()

console.log('4 condiciones:',true && true && true && true && false); // false

console.warn('OR') // true si alguno de los valores son verdaderos

console.log(true || false); // true
console.log(false || false); // false

console.log(regresaTrue() || regresaFalse()); // true
console.log(regresaFalse() || regresaTrue()); // true
console.log('4 condiciones:', true || true || true || true || false); // true

console.warn('Asignaciones');

const soyUndefined = undefined;
const soyNull = null;
const soyFalso = false;

const a1 = false && 'Hola Mundo' && 150;
const a2 = 'Hola' && 'Mundo' && soyFalso;
const a3 = soyFalso || 'Ya no soy falso';
const a4 = soyFalso || soyUndefined || soyNull || 'Ya no soy falso de nuevo' || true;
const a5 = soyFalso || soyUndefined || regresaTrue() || 'Ya no soy falso de nuevo' || true;

console.log({a1, a2, a3, a4, a5});

if ( regresaTrue() || regresaFalse() && (true || false || true) ){
console.log('Hacer algo');
} else {
console.log('Hacer otra cosa');
}
File renamed without changes.
34 changes: 34 additions & 0 deletions assets/js/bases/operador-ternario.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Dias de semana abrimos a las 11,
* pero los fines de semana abrimos a las 9
*/

// Entra a un sitio web, para consultar si esta abierto hoy....

const dia = 1; // 0: Domingo... 1: Lunes....
const horaActual = 11;

let horaApertura;
let mensaje; // = (dia === 0 || dia === 6) ? 'Fin de semana' : 'Día de semana' // Esta abierto, Está cerrado, hoy abrimos a las XX

// if (dia === 0 || dia === 6){
// if ( [0,6].includes(dia) ){
// console.log('Fin de semana');
// horaApertura = 9;
// } else {
// console.log('Día de semana');
// horaApertura = 11;
// }

//[0,6].includes(dia) ESTO es very good condition
horaApertura = ([0,6].includes(dia)) ? 9 : 11;

// if (horaActual >= horaApertura){
// mensaje = 'Esta abierto';
// } else {
// mensaje = `Está cerrado, hoy abrimos a las ${horaApertura}`;
// }

mensaje = (horaActual >= horaApertura) ? 'Esta abierto' : `Está cerrado, hoy abrimos a las ${horaApertura}`;

console.log({horaApertura, mensaje})
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions assets/js/bases/protip-ternario.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// const elMayor = (a, b) => {
// return (a > b) ? a : b;
// }
const elMayor = (a, b) => (a > b) ? a : b;

const tieneMembresia = (miembro) => (miembro) ? '2 Dólares' : '10 Dólares';


console.log(elMayor(20,15));
console.log(tieneMembresia(false));


const amigo = false;
const amigosArr = [
'Peter',
'Tony',
'Dr. Strange',
(amigo) ? 'Thor' : 'Loki',
(() => 'Nick Fury')(),
elMayor(10,15)
];

console.log(amigosArr);

const nota = 82.5; // A+ A B+
const grado = (nota >= 95) ? 'A+' :
(nota >= 90) ? 'A' :
(nota >= 85) ? 'B+' :
(nota >= 80) ? 'B' :
(nota >= 75) ? 'C+' :
(nota >= 70) ? 'C' : 'F';

console.log({nota,grado});
20 changes: 20 additions & 0 deletions assets/js/bases/switch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const dia = 0; // 0: Domingo..

switch (dia) {
case 0:
console.log('Domingo'); break;
case 1:
console.log('Lunes'); break;
case 2:
console.log('Martes'); break;
case 3:
console.log('Miércoles'); break;
case 4:
console.log('Jueves'); break;
case 5:
console.log('Viernes'); break;
case 6:
console.log('Sábado'); break;
default:
console.log('No es un día válido'); break;
}
38 changes: 38 additions & 0 deletions assets/js/bases/valor-referencia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
let a = 10;
let b = a;
a = 30;

console.log(a,b);


let juan = { nombre: 'Juan'};
let ana = {...juan};
ana.nombre = 'Ana';

console.log(juan,ana);

const cambiaNombre = ({...persona}) => {
persona.nombre = 'Tony';
return persona;
}

let peter = { nombre: 'Peter' };
let tony = cambiaNombre(peter);

console.log({peter,tony});


// Arrays
const frutas = ['Manzanas','Pera','Piña'];
// const otrasFrutas = [...frutas];
console.time('slice');
const otrasFrutas = frutas.slice();
console.timeEnd('slice');

console.time('spread');
const otrasFrutas2 = [...frutas];
console.timeEnd('spread');

otrasFrutas.push('Mango');

console.table({frutas,otrasFrutas})
17 changes: 17 additions & 0 deletions assets/js/ciclos/for.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const heroes = ['Batman','Superman','Mujer Maravilla', 'Aquaman'];

console.warn('For tradicional');

for( let i = 0; i < heroes.length; i++ ){
console.log(heroes[i]);
}

console.warn('For in');
for( let i in heroes ){
console.log(heroes[i]);
}

console.warn('For of');
for( let heroe of heroes ) {
console.log(heroe);
}
38 changes: 38 additions & 0 deletions assets/js/ciclos/while-do-while.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const coches = ['Ford','Mazda','Honda','Toyota'];

let i = 0;

// while( i < coches.length ){
// console.log(coches[i]);
// // i = i + 1
// // i += 1;
// i++;
// }

// Son Evaluados como un false y el while no se ejecutaria
//
// undefined
// null
// false

// console.log(coches[10]);
// while( i < coches.length ){ // Seria igual que el codigo de abajo, pero el de abajo es mas limpio, cuando i se salga del length del array devolveria un undefined que es lo mismo que un false en un while, por eso se detendria el while
console.warn('While')
while( coches[i] ){
if ( i === 1){
// break;
i++;
continue;
}
console.log(coches[i]);
i++;
}

console.warn('Do While')

let j = 0;

do {
console.log(coches[j]);
j++;
} while (coches[j]);
19 changes: 17 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,22 @@ <h1>Hola Mundo</h1>
console.log('Hola Mundo en HTML')
</script> -->

<!-- <script src="assets/js/app.js"></script> -->
<script src="assets/js/alerts.js"></script>
<!-- <script src="assets/js/bases/app.js"></script> -->
<!-- <script src="assets/js/bases/alerts.js"></script> -->
<!-- <script src="assets/js/bases/primitivos.js"></script> -->
<!-- <script src="assets/js/bases/palabras-reservadas.js"></script> -->
<!-- <script src="assets/js/bases/arreglos.js"></script> -->
<!-- <script src="assets/js/bases/arreglos2.js"></script> -->
<!-- <script src="assets/js/bases/objeto-literal.js"></script> -->
<!-- <script src="assets/js/bases/funciones.js"></script> -->
<!-- <script src="assets/js/bases/protip-retorno.js"></script> -->
<!-- <script src="assets/js/bases/valor-referencia.js"></script> -->
<!-- <script src="assets/js/bases/if-else.js"></script> -->
<!-- <script src="assets/js/bases/logica-booleana.js"></script> -->
<!-- <script src="assets/js/bases/operador-ternario.js"></script> -->
<!-- <script src="assets/js/bases/protip-ternario.js"></script> -->
<!-- <script src="assets/js/bases/switch.js"></script> -->
<!-- <script src="assets/js/ciclos/while-do-while.js"></script> -->
<script src="assets/js/ciclos/for.js"></script>
</body>
</html>

0 comments on commit 2a1ec27

Please sign in to comment.