This commit is contained in:
Marcos Lopez
2024-01-17 13:51:01 +01:00
parent f86dee8067
commit ad08f8d30d
13 changed files with 617 additions and 1 deletions

View File

@@ -0,0 +1,66 @@
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Prueba funciones cadenas de texto</title>
</head>
<body>
<script>
var texto1="En un lugar de la Mancha, de cuyo nombre no quiero acordarme, no ha mucho tiempo que vivía un hidalgo de los de lanza en astillero, adarga antigua, rocín flaco y galgo corredor";
var texto2="Una olla de algo más vaca que carnero, salpicón las más noches, duelos y quebrantos los sábados ...";
// Contar las "u" en texto1
document.write(texto1.split("u").length-1);
document.write("<br>");
// Cuantos caracters en texto2
document.write(texto2.length + "<br>");
// Cual es el septimo caracter del texto2 ?
document.write(texto2.charAt(6) + "<br>");
//Une las dos cadenas de texto iniciales ?
document.write(texto1 + texto2 + "<br>");
var textoConcatenado = texto1.concat(texto2);
// Haz que el texto2 termine con la siguiente frase " y película los viernes".
//document.write(texto2 + " y película los viernes.") + "<br>");
document.write(texto2.concat(" y película los viernes.") + "<br>");
//texto2 += " y película los viernes"; -=, *=, y /=
// En que posición esta la primera palabra "un" a partir de la palabra Mancha ?
//indexOf(valor a buscar, desde que posición empieza)
document.write((texto1.indexOf("Mancha") + 5) + "<br>");
document.write(texto1.indexOf("un",24) + "<br>");
// En que posición esta el último "de" del texto1 ?
document.write(texto1.lastIndexOf("de") + "<br>");
// Haz que las palabras que componen el texto2 aparezcan separadas por comas.
document.write(texto2.split(" ") + "<br>");
// ** Cuantas palabras compone el texto2
document.write(texto2.split(" ").length + "<br>");
// 1 Con lo que sabemos
var palabras=texto1.split(" "); // Crea array
// Bucle para escribir
for ( var i = 0; i < palabras.length; i = i + 1) {
document.write(palabras[i] + "<br>");
}
// 2 Con join
document.write(texto1.split(" ").join("<br>"));
</script>
</body>
</html>

View File

@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lista de invitados</title>
<link rel="stylesheet" href="css/estilos.css" />
</head>
<body>
<h1>Lista de Invitados</h1>
<button onclick="agregarInvitado()">Agregar Invitado</button>
<button onclick="verLista()">Ver Lista</button>
<button onclick="borrarLista()">Borrar Lista</button>
<script>
// Array para almacenar la lista de invitados
let listaInvitados = [];
// Función para agregar un nuevo invitado a la lista
function agregarInvitado() {
let nombreInvitado = prompt("Ingrese el nombre del invitado:");
if (nombreInvitado !== null && nombreInvitado !== '') {
listaInvitados.push(nombreInvitado);
alert(`Invitado ${nombreInvitado} agregado a la lista.`);
}
}
// Función para ver la lista de invitados
function verLista() {
if (listaInvitados.length === 0) {
alert("La lista de invitados está vacía.");
} else {
let listaTexto = "Lista de Invitados:\n";
listaInvitados.forEach(function (invitado, indice) {
listaTexto += `${indice + 1}. ${invitado}\n`;
});
alert(listaTexto);
}
}
// Función para borrar la lista de invitados con confirmación
function borrarLista() {
let confirmacion = confirm("¿Estás seguro de que deseas borrar la lista de invitados?");
if (confirmacion) {
listaInvitados = []; // Borrar la lista
alert("La lista de invitados ha sido borrada.");
}
}
</script>
</body>
</html>

View File

@@ -15,7 +15,7 @@
<br>
<br>
<script>
//document.write(`Numero de caracteres 'u' en texto1: ${texto1.split('u').length-1}`) - falla cuando la ultima letra es la que buscas, habria que controlarlo
//document.write(`Numero de caracteres 'u' en texto1: ${texto1.split('u').length-1}`)
let contador = 0;
for (let i = 0; i < texto1.length; i++) {
if (texto1.charAt(i) === 'u') {