-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculadora.html
52 lines (50 loc) · 1.16 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
<!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="+">mas</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>
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>