-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexo4.html
More file actions
55 lines (51 loc) · 1.48 KB
/
exo4.html
File metadata and controls
55 lines (51 loc) · 1.48 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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>KDJS TD n°3</title>
<style>
/* Du bon style */
</style>
<script src="angular.min.js"></script>
</head>
<body>
<div ng-app="calculette" ng-controller="controlleur01">
<input type="number" ng-model="nb1">
<input type="number" ng-model="nb2">
<select ng-model="operator">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<p>{{ result() }}</p>
</div>
<script>
var app = angular.module("calculette", []);
app.controller("controlleur01", function($scope) {
$scope.operator = "+";
$scope.result = function() {
var calcul = 0;
if (!this.nb1 || !this.nb2) {
return "Entrez deux chiffres";
}
switch (this.operator) {
case "+":
calcul = parseInt(this.nb1) + parseInt(this.nb2);
break;
case "-":
calcul = parseInt(this.nb1) - parseInt(this.nb2);
break;
case "*":
calcul = parseInt(this.nb1) * parseInt(this.nb2);
break;
case "/":
calcul = parseInt(this.nb1) / parseInt(this.nb2);
break;
}
return this.nb1 + " " + this.operator + " " + this.nb2 + " = " + calcul;
}
});
</script>
</body>
</html>