81 lines
2.5 KiB
HTML
81 lines
2.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Arrays 02</title>
|
|
<link rel="stylesheet" href="../Introduccion/estilos.css">
|
|
<script>
|
|
let clasificaciones = ['Ana', 'Oswaldo', 'Raúl', 'Celia', 'María', 'Antonio'];
|
|
|
|
function muestraClasificacion() {
|
|
clasificaciones.forEach((el, index) => {
|
|
document.write((index + 1) + '-' + el + '<br>')
|
|
})
|
|
document.write('<br>')
|
|
}
|
|
|
|
function muestraClasificacionAlert() {
|
|
let text = '';
|
|
clasificaciones.forEach((el, index) => {
|
|
text = text + (index + 1) + '-' + el + '\n'
|
|
})
|
|
alert(text)
|
|
}
|
|
|
|
function eliminarParticipante(participante) {
|
|
index = clasificaciones.indexOf(participante)
|
|
console.log(index)
|
|
if (index != -1) {
|
|
clasificaciones.splice(index, 1);
|
|
} else {
|
|
alert('Participante no encontrado');
|
|
}
|
|
}
|
|
|
|
|
|
function adelantaParticipante(participante, adelantado){
|
|
indexParticipante=clasificaciones.indexOf(participante);
|
|
indexAdelantado=clasificaciones.indexOf(adelantado);
|
|
clasificaciones[indexAdelantado]=participante;
|
|
clasificaciones[indexParticipante]=adelantado;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
</head>
|
|
|
|
<body>
|
|
<script>
|
|
// document.write('Clasificacion provisional:' + '<br>')
|
|
// muestraClasificacion();
|
|
|
|
// document.write('Celia adelanta a Raul:' + '<br>')
|
|
// clasificaciones[3] = 'Raúl'
|
|
// clasificaciones[2] = 'Celia'
|
|
// muestraClasificacion();
|
|
|
|
// document.write('Antonio es eliminado:' + '<br>')
|
|
// clasificaciones.pop();
|
|
// muestraClasificacion();
|
|
|
|
// document.write('Se clasifican Roberto y Amaya' + '<br>')
|
|
// clasificaciones.splice(1, 0, 'Roberto', 'Amaya');
|
|
// muestraClasificacion();
|
|
|
|
// document.write('Nueva participante que pasa a encabezar la clasificación: Marta' + '<br>')
|
|
// clasificaciones.unshift('Marta');
|
|
// muestraClasificacion();
|
|
|
|
</script>
|
|
<button onclick="eliminarParticipante(prompt('¿A quien quieres eliminar?'))">Eliminar Participante</button>
|
|
<button onclick="adelantaParticipante(prompt('Participante'),prompt('Adelantado'))">Adelanta Participante</button>
|
|
|
|
<button onclick="muestraClasificacionAlert()">Ver Clasificacion</button>
|
|
</body>
|
|
|
|
</html> |