Skip to content

Instantly share code, notes, and snippets.

@DavidPeralvarez

DavidPeralvarez/chuleta.txt Secret

Created Apr 2, 2020
Embed
What would you like to do?
JavaScript - If...Else, Operadores de Comparación y Operadores Lógicos
/* Operadores de comparación
== igual
=== igual y del mismo tipo
>
<
>=
<=
!=
*/
/* Operadores lógicos
&& y
|| o
! negación
*/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Curso de Javascript</title>
</head>
<body>
<script src="scripts.js"></script>
</body>
</html>
/* If...Else */
// Tamagotchi
var tamagotchi = {
hambre: 1,
aburrimiento: 4,
cansancio: 9,
vivo: false
};
if ( tamagotchi.hambre <= 1 ) {
console.log( 'Voy a morir de inanición' );
} else if ( tamagotchi.hambre < 5 ) {
console.log( 'Dame de comer' );
} else {
console.log( 'Estoy saciado' );
}
if ( ( tamagotchi.aburrimiento < 5 ) || ( tamagotchi.cansancio < 5 ) ) {
console.log( 'Ponme una serie en Netflix' );
if( tamagotchi.hambre < 5 ) {
console.log( 'Hazme una palomitas' );
}
}
if ( !tamagotchi.vivo ) {
console.log( 'Me has matado mala persona' );
}
if ( 0 === false ) {
console.log( 'son iguales' );
}
if ( 'hola' != 'adios' ) {
console.log( 'son distintos' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.