This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function factorial(numero) { | |
| if (numero === 1) { | |
| return 1; | |
| } | |
| return numero * factorial(numero - 1); | |
| } | |
| var resultado = factorial(5); | |
| console.log(resultado); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var numero = prompt("Ingrese un número"); | |
| numero = Number(numero); | |
| if (numero === 0) { | |
| alert("Cero"); | |
| } else if (numero > 0) { | |
| alert("Positivo"); | |
| } else { | |
| alert("Negativo"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Error lógico | |
| */ | |
| // Función que espera 2 números como parámetros para devolver la suma de ambos | |
| var suma = function (num1, num2) { | |
| return num1 + num2; | |
| }; | |
| // Imaginemos que el número 1 es 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Errores de sintaxis | |
| */ | |
| // Nombre de variable con tilde | |
| var número = 10; | |
| // Error de operador: = es asignación, mientras, == es comparación, y, === es comparación estricta | |
| if (numero = 0) { | |
| console.log("Cero"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var init = function () { | |
| var estudiantes = listaEstudiantes(); | |
| ordenarEstudiantes(estudiantes); | |
| }; | |
| var listaEstudiantes = function () { | |
| var numeroEstudiantes = parseInt(prompt("¿Cuántos estudiantes vas a registrar?")); | |
| var estudiantes = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var numeroEstudiantes = parseInt(prompt("¿Cuántos estudiantes vas a registrar?")); | |
| var estudiantes = []; | |
| document.write("<h1>Lista de Estudiantes</h1>"); | |
| for (var i = 0; i < numeroEstudiantes; i++) { | |
| var nombre = prompt("Nombre del estudiante #" + (i+1)); | |
| var apellido = prompt("Apellido del estudiante #" + (i+1)); | |
| var estudiante = { | |
| nombre: nombre, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var numeroEstudiantes = parseInt(prompt("Dame el # de estudiantes")); | |
| var estudiantes = []; | |
| for (var i = 0; i < numeroEstudiantes; i++) { | |
| var nombre = prompt("Ingresa el nombre " + i); | |
| var apellidos = prompt("Ingresa el apellido " + i); | |
| var estudiante = {}; | |
| estudiante.nombre = nombre; | |
| estudiante.apellidos = apellidos; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // IIFE | |
| (function () { | |
| var preguntar = function (pregunta) { | |
| var respuesta = prompt(pregunta); | |
| return respuesta.toUpperCase(); | |
| }; | |
| var esRespuestaCorrecta = function (respuesta, respuestaCorrecta) { | |
| if (respuesta === respuestaCorrecta) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var preguntar = function (pregunta) { | |
| var respuesta = prompt(pregunta); | |
| return respuesta.toUpperCase(); | |
| }; | |
| var esRespuestaCorrecta = function (respuesta, respuestaCorrecta) { | |
| if (respuesta === respuestaCorrecta) { | |
| return true; | |
| } else { | |
| return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Hoisting | |
| // var saludo; | |
| // var nombre; | |
| // var numero; | |
| // console.log(typeof saludo); | |
| // console.log(saludo("Ivan")); | |
| // Function Expression | |
| // -------- ---------- | |
| // Función como valor (Function as value) |