-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculadora.html
More file actions
140 lines (116 loc) · 2.73 KB
/
Copy pathcalculadora.html
File metadata and controls
140 lines (116 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculadora JS</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
font-family: arial;
background: #ccc;
color: #3ba8db;
}
.contenedor{
width: 70%;
margin: 100px auto;
background: #21295c;
padding: 20px;
display: flex;
align-items: center;
flex-direction: column;
}
.inputs{
width: 80%;
display: flex;
flex-direction: row;
justify-content: space-between;
}
.inputs input{
width: 50%;
margin: 10px;
padding: 20px;
text-align: center;
font-size: 25px;
font-weight: 600;
color: #21295c;
}
.btns{
display: flex;
flex-direction: row;
width: 80%;
justify-content: space-around;
}
.btns button{
width: 25%;
height: 50px;
margin: 10px;
cursor: pointer;
text-transform: uppercase;
font-weight: 700;
font-size: 14px;
background: #3ba8db;
color: #fff;
border: 0;
transition: all 0.3s;
}
.btns button:hover{
background: #92f8ff80;
}
.result{
display: flex;
flex-direction: row;
justify-content: center;
width: 80%;
margin: 30px 0 10px 0;
}
.result p{
color: #fff;
font-size: 45px;
font-weight: 700;
}
</style>
</head>
<body>
<div class="contenedor">
<div id="inputs" class="inputs">
<input type="number" id="numero1">
<input type="number" id="numero2">
</div>
<div id="btns" class="btns">
<button id="suma">Sumar</button>
<button id="resta">Restar</button>
<button id="multiplica">Multiplicar</button>
<button id="divide">Dividir</button>
</div>
<div class="result">
<p id="resultado">-</p>
</div>
</div>
<script type="text/javascript">
var operaciones = function (e) {
var num1 = parseFloat(document.getElementById("numero1").value);
var num2 = parseFloat(document.getElementById("numero2").value);
var result = document.getElementById("resultado");
var opciones = e.target.id;
if(opciones == "suma"){
var resultado = num1 + num2;
} else if (opciones == "resta"){
var resultado = num1 - num2;
}else if (opciones == "multiplica"){
var resultado = num1 * num2;
} else if (opciones == "divide"){
var resultado = num1 / num2;
}
result.innerHTML = resultado;
}
//Obetemos el evento en el contenedor padre de los botones
var botones = document.getElementById("btns");
botones.addEventListener("click", operaciones);
</script>
</body>
</html>