-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcalculadora.html
54 lines (48 loc) · 1.18 KB
/
calculadora.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Calculadora</title>
</head>
<body>
<h1>Calculadora</h1>
<label for="var-a">variable a</label>
<input type="text" id="var-a">
<select id="operador">
<option value="+">más</option>
<option value="-">menos</option>
<option value="*">por</option>
<option value="/">divido por</option>
</select>
<label for="var-b">variable b</label>
<input type="text" id="var-b">
<button id="calcular">calcular</button>
<input type="text" id="resultado">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
//Nuestro código
var $vara = $('#var-a'),
$varb = $('#var-b'),
$operador = $('#operador'),
$calcular = $('#calcular'),
$resultado = $('#resultado');
function calcular(){
var op, a, b, res;
a = parseInt( $vara.val() );
b = parseInt( $varb.val() );
op = $operador.val();
if( op == '+' ){
res = a + b
}else if( op == '-' ){
res = a - b
}else if( op == '*' ){
res = a * b
}else{
res = a / b
}
$resultado.val( res )
}
$calcular.on('click', calcular)
</script>
</body>
</html>