Curso Básico de JavaScript
Curso Básico de JavaScript
¿Qué es JavaScript?
En línea:
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Básico</title>
</head>
<body>
<h1>Hola, Mundo</h1>
<script>
alert('¡Bienvenido a JavaScript!');
</script>
</body>
</html>
En un archivo externo:
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Externo</title>
<script src="script.js"></script>
</head>
<body>
<h1>Hola, Mundo</h1>
</body>
</html>
Archivo script.js:
Actividad:
Declaración de variables:
Tipos de datos:
• Number: Números.
Actividad:
3. console.log(nombre);
4. console.log(edad);
Operadores:
let suma = 5 + 3; // 8
let resta = 10 - 7; // 3
let multiplicacion = 4 * 2; // 8
let division = 20 / 5; // 4
Actividad:
1. Crea un script que realice las operaciones básicas con dos números.
Lección 4: Condicionales
Sintaxis básica:
} else {
Actividad:
Lección 5: Bucles
Bucle for:
Bucle while:
let i = 0;
while (i < 5) {
i++;
}
Actividad:
Lección 6: Funciones
Definición de funciones:
function saludar(nombre) {
console.log(saludar("Ana"));
Actividad:
Modificar contenido:
<!DOCTYPE html>
<html>
<head>
<title>Interacción</title>
</head>
<body>
<h1 id="titulo">Hola</h1>
<script>
function cambiarTexto() {
}
</script>
</body>
</html>
Actividad:
Desafío:
Ejemplo Final:
<!DOCTYPE html>
<html>
<head>
<title>Proyecto Final</title>
</head>
<body>
<h2>Formulario</h2>
<label for="nombre">Nombre:</label>
<label for="edad">Edad:</label>
<button onclick="saludar()">Saludar</button>
<p id="saludo"></p>
<h2>Contador</h2>
<button onclick="incrementar()">Incrementar</button>
<p id="contador">0</p>
<script>
function saludar() {
let contador = 0;
function incrementar() {
contador++;
document.getElementById("contador").innerHTML = contador;
</script>
</body>
</html>