mirror of
https://github.com/CristianCruz0309/proyectos-curso-javascript.git
synced 2026-08-15 02:50:10 +00:00
Proyectos (DIA 1 - 13)
Realizados gracias al curso "JAVASCRIPT TOTAL"
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Calculadora</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
<script src="script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="calculadora">
|
||||
<h1>Calculadora</h1>
|
||||
|
||||
<input type="text" id="campo1">
|
||||
<input type="text" id="campo2">
|
||||
|
||||
<div class="operaciones">
|
||||
<button onclick="suma()">+</button>
|
||||
<button onclick="resta()">-</button>
|
||||
<button onclick="multiplicacion()">*</button>
|
||||
<button onclick="division()">/</button>
|
||||
</div>
|
||||
|
||||
<div class="doble">
|
||||
<button onclick="raiz()">Raíz</button>
|
||||
<button onclick="potencia()">Potencia</button>
|
||||
<button onclick="absoluto()">Absoluto</button>
|
||||
<button onclick="aleatorio()">Random</button>
|
||||
</div>
|
||||
|
||||
<h3>Resultado:</h3>
|
||||
<input type="text" id="resultado">
|
||||
|
||||
<div class="triple">
|
||||
<button onclick="redondeo()">Round</button>
|
||||
<button onclick="piso()">Floor</button>
|
||||
<button onclick="techo()">Ceil</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,68 @@
|
||||
function mostrarResultado(resultado) {
|
||||
document.getElementById("resultado").value = resultado;
|
||||
}
|
||||
|
||||
function suma() {
|
||||
let numero1 = +document.getElementById("campo1").value;
|
||||
let numero2 = +document.getElementById("campo2").value;
|
||||
mostrarResultado(numero1 + numero2);
|
||||
}
|
||||
|
||||
function resta() {
|
||||
let numero1 = +document.getElementById("campo1").value;
|
||||
let numero2 = +document.getElementById("campo2").value;
|
||||
mostrarResultado(numero1 - numero2);
|
||||
}
|
||||
|
||||
function multiplicacion() {
|
||||
let numero1 = +document.getElementById("campo1").value;
|
||||
let numero2 = +document.getElementById("campo2").value;
|
||||
mostrarResultado(numero1 * numero2);
|
||||
}
|
||||
|
||||
function division() {
|
||||
let numero1 = +document.getElementById("campo1").value;
|
||||
let numero2 = +document.getElementById("campo2").value;
|
||||
mostrarResultado(numero1 / numero2);
|
||||
}
|
||||
|
||||
function raiz() {
|
||||
let numero = +document.getElementById("campo2").value;
|
||||
mostrarResultado(Math.sqrt(numero));
|
||||
}
|
||||
|
||||
function potencia() {
|
||||
let numero1 = +document.getElementById("campo1").value;
|
||||
let numero2 = +document.getElementById("campo2").value;
|
||||
mostrarResultado(Math.pow(numero1, numero2));
|
||||
}
|
||||
|
||||
function absoluto() {
|
||||
let numero = +document.getElementById("campo2").value;
|
||||
mostrarResultado(Math.abs(numero));
|
||||
}
|
||||
|
||||
function aleatorio() {
|
||||
let minimo = +document.getElementById("campo1").value;
|
||||
let maximo = +document.getElementById("campo2").value;
|
||||
maximo = maximo + 1;
|
||||
mostrarResultado(Math.floor(Math.random() * (maximo - minimo) + minimo));
|
||||
}
|
||||
|
||||
function redondeo() {
|
||||
let resultado = +document.getElementById("resultado").value;
|
||||
mostrarResultado(Math.round(resultado));
|
||||
}
|
||||
|
||||
function techo() {
|
||||
let resultado = +document.getElementById("resultado").value;
|
||||
mostrarResultado(Math.ceil(resultado));
|
||||
}
|
||||
|
||||
function piso() {
|
||||
let resultado = +document.getElementById("resultado").value;
|
||||
mostrarResultado(Math.floor(resultado));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
body {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
background-color: #f2f2f2;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.calculadora {
|
||||
background-color: white;
|
||||
padding: 20px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 20px rgba(0,0,0,0.2);
|
||||
text-align: center;
|
||||
width: 260px;
|
||||
}
|
||||
|
||||
input {
|
||||
width: 90%;
|
||||
height: 30px;
|
||||
font-size: 1rem;
|
||||
margin: 5px 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.operaciones {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
button {
|
||||
height: 40px;
|
||||
width: 45px;
|
||||
font-size: 1.2rem;
|
||||
font-weight: bold;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
background-color: #4caf50;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.triple {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.doble {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 8px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.doble button {
|
||||
width: 100%;
|
||||
padding: 8px 4px;
|
||||
background-color: #2196f3;
|
||||
font-size: 0.85rem;
|
||||
white-space: nowrap;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.triple button {
|
||||
width: 70px;
|
||||
background-color: #ff9800;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
#resultado {
|
||||
font-weight: bold;
|
||||
}
|
||||
Reference in New Issue
Block a user