Commit 70bb8af8 by Cristhian Ortellado

Se termino la tarea nro 3 de javascript

parents
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 1</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<h1>Observe la piramide del poder </h1>
<ul id="lista-primos">
</ul>
</body>
<script src="js/main.js"></script>
</html>
\ No newline at end of file
ul li {
list-style: none;
height: 20px;
margin: 0 auto 2px auto;
background-color: rgb(127, 255, 0);
border-radius: 10%;
}
* {
text-align: center;
font-family: sans-serif;
}
body {
background-color: #fafafa;
}
\ No newline at end of file
//variable para agregar al html los numeros primos
var ul = document.getElementById("lista-primos");
//funcion para generar numeros primos
function numerosPrimos() {
for (let i = 2; i <= 100; i++) {
if (esPrimo(i)) {
//creamos el nodo y le agregamos un elemento
var li = document.createElement("li");
li.innerHTML = i;
//le agrego unos estilos para que sea mas bello a la vista
li.style.width = i + '%';
li.style.backgroundColor = "rgb(150," + i * 2 + ", 20)";
ul.appendChild(li);
}
}
}
//funcion para saber si un numero es primo o no
function esPrimo(numero) {
var contador = 2;
for (let i = 1; i < numero / 2; i++) {
if (numero % contador == 0) {
return false;
}
contador++;
}
return true;
}
numerosPrimos();
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 10</title>
</head>
<body>
</body>
<script src="js/main.js"></script>
</html>
\ No newline at end of file
function esPalindrome(palabra) {
var conReversa = palabra.length;
for (let i = 1; i <= (palabra.length) / 2; i++) {
if (palabra[i - 1] != palabra[conReversa - i]) {
return false;
}
}
return true;
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 11</title>
</head>
<body>
</body>
<script src="js/main.js"></script>
</html>
\ No newline at end of file
function estaOrdenado(array) {
for (let i = 0; i < array.length - 1; i++)
if (array[i] > array[i + 1])
return "El arreglo no esta ordenado";
return "El arreglo esta ordenado";
}
var vector = [1, 2, 3, 6, 7, 8, 15];
console.log(estaOrdenado(vector));
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 12</title>
</head>
<body>
</body>
<script src="js/main.js"></script>
</html>
\ No newline at end of file
function incrementarArray(array) {
for (let i = 0; i < array.length; i++) {
array[i]++;
}
return array;
}
var vector = [1, 2, 3, 6, 7, 8, 15];
console.log(incrementarArray(vector)); * /
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 13</title>
</head>
<body>
</body>
<script src="js/main.js"></script>
</html>
\ No newline at end of file
//usamos burbleSort mejorado
function ordenar(array) {
var auxiliar = 0; //variable para intercambio de valores
var cambio = true; //si nunca se realiza un cambio entonces el array esta ordenado
for (let i = 0; i < array.length / 2 + 1 && cambio; i++) {
cambio = false;
for (let j = 0; j < array.length - i - 1; j++) {
if (array[j] > array[j + 1]) {
auxiliar = array[j];
array[j] = array[j + 1];
array[j + 1] = auxiliar;
cambio = true;
}
}
}
return array;
}
var vector = [9, 5, 7, 8, 1, 3];
console.log(ordenar(vector));
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 14</title>
</head>
<body>
</body>
<script src="js/main.js"></script>
</html>
\ No newline at end of file
function intercambiar(array, i, j) {
var lon = array.length;
//si los parametros son validos realiza el cambio
if (i > -1 && i < lon && j > -1 && j < lon) {
var auxiliar = array[i];
array[i] = array[j];
array[j] = auxiliar;
} else {
console.log("Indice fuera de rango");
}
return array;
}
var vector = [9, 5, 7, 8, 1, 3];
console.log(intercambiar(vector, 0, 5)); * /
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 15</title>
</head>
<body>
</body>
<script src="js/main.js"></script>
</html>
\ No newline at end of file
function promedio(array) {
var promedio = 0;
var sum = 0;
for (let i = 0; i < array.length; i++) {
sum += array[i];
}
promedio = sum / array.length;
return promedio;
}
var vector = [9, 5, 7, 8, 1, 3];
console.log(promedio(vector));
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 16</title>
</head>
<body>
</body>
<script src="js/main.js"></script>
</html>
\ No newline at end of file
//array con los dias de la semana
var dias = [1, 2, 3, 4, 5, 6, 7];
//prueba
console.log(diaSemana(dias[6]));
function diaSemana(diaNumero) {
switch (diaNumero) {
case 1:
return 'LUNES';
break;
case 2:
return 'MARTES';
break;
case 3:
return 'MIERCOLES';
break;
case 4:
return 'JUEVES';
break;
case 5:
return 'VIERNES';
break;
case 6:
return 'SABADO';
break;
case 7:
return 'DOMINGO';
break;
default:
console.log("El dia introducido no es valido");
break;
}
//si el dia introducido no es valido
return -1;
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 2</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<h1>El factorial de los primeros 50 numeros </h1>
</body>
<script src="js/main.js"></script>
</html>
\ No newline at end of file
* {
text-align: center;
font-family: sans-serif;
}
body {
background-color: #fafafa;
}
ul {
list-style: none;
}
li {
text-align: justify;
margin-bottom: 10px;
}
span {
color: rgb(6, 150, 1);
font-weight: 900;
background-color: black;
border-radius: 10%;
padding: 4px;
}
\ No newline at end of file
//funcion para imprimir los factoriales
function imprimirFactorial() {
//creamos una lista para pegarla en el html
var ul = document.createElement('ul');
for (let i = 1; i <= 50; i++) {
//obtenemos el factorial del numero
var numero = factorial(i);
//creamos el nodo y le agregamos un elemento
var li = document.createElement("li");
li.innerHTML = "El factorial de " + i + " es -> " + '<span>' + numero + '</span>';
ul.appendChild(li);
console.log("oli");
}
//agregamos al body
var cuerpo = document.body;
cuerpo.appendChild(ul);
}
//funcion para hallar los factoriales
function factorial(numero) {
var aux = 1;
for (let i = 1; i <= numero; i++) {
aux = aux * i;
}
return aux;
}
imprimirFactorial();
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 3</title>
</head>
<body>
<h1>El ejercicio se mostrara en la consola: Ingrese su numero desde el codigo js</h1>
</body>
<script src="js/main.js">
</script>
</html>
\ No newline at end of file
function comprobarNumero(numero) {
if (numero % 5 == 0 && numero % 11 == 0) {
console.log("Si es divisible por 5 y 11 ");
} else {
console.log("No es divisible por 5 y 11 ");
}
}
comprobarNumero(25);
comprobarNumero(55);
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 4</title>
</head>
<body>
<h1>El ejercicio se muestra en la consola, ingrese el numero deseado en el codigo js</h1>
</body>
<script src="js/main.js"></script>
</html>
\ No newline at end of file
function edad(edad) {
if (edad >= 18) {
console.log('Es mayor de edad');
} else {
console.log('No es mayor de edad');
}
}
//ingrese los numeros
edad(15);
edad(18);
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 5</title>
</head>
<body>
</body>
<script src="js/main.js">
</script>
</html>
\ No newline at end of file
var numero1 = parseInt(prompt("Ingrese el primer numero"));
var numero2 = parseInt(prompt("Ingrese el primer numero"));
alert("La suma es " + (numero1 + numero2));
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 6</title>
</head>
<body>
</body>
<script src="js/main.js"></script>
</html>
\ No newline at end of file
var temperatura = parseFloat(prompt("Ingrese la temperatura en Celcius"));
//realizamos la convercion
var faren = 1.8 * temperatura + 32;
alert("La temperatura en Fahrenheit es " + faren);
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 7</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
var numero = parseFloat(prompt("Ingrese un numero"));
var operacion = numero / 10;
alert("La division es " + operacion);
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 8</title>
</head>
<body>
</body>
<script src="js/main.js"></script>
</html>
\ No newline at end of file
function diaSemana(dia) {
var diaM = dia.toUpperCase();
switch (diaM) {
case 'LUNES':
return 1;
break;
case 'MARTES':
return 2;
break;
case 'MIERCOLES':
return 3;
break;
case 'JUEVES':
return 4;
break;
case 'VIERNES':
return 5;
break;
case 'SABADO':
return 6;
break;
case 'DOMINGO':
return 7;
break;
default:
console.log("El dia introducido no es valido");
break;
}
//si el dia introducido no es valido
return -1;
}
//ingrese el dia que desea saber
console.log(diaSemana('jueves'));
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ejercicio 9</title>
</head>
<body>
</body>
<script src="js/main.js"></script>
</html>
\ No newline at end of file
//la funcion suma los pares entre los numeros sin incluir los extremos
function sumaPares(rangoInferior, rangoSuperior) {
//acumulador para sumar los numeros pares
var sum = 0;
for (let i = ++rangoInferior; i < rangoSuperior; i++)
if (i % 2 == 0)
sum += i;
return sum;
}
console.log(sumaPares(1, 5));
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment