-
Notifications
You must be signed in to change notification settings - Fork 7
/
10-operators.html
52 lines (38 loc) · 1.43 KB
/
10-operators.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">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Demo</title>
</head>
<body>
<script type="text/javascript">
// Fun with operators
var simpleMath = 10 / 3;
var modMath = 10 % 3;
// because I hate writing this over and over
var lineBreak = '</br>';
// output the full value
document.write(simpleMath + lineBreak);
// output the remainder or mod
document.write(modMath + lineBreak);
// output the nearest integer
document.write(Math.round(simpleMath) + lineBreak);
// output the rounded up integer
document.write(Math.ceil(simpleMath) + lineBreak);
// output the rounded down integer
document.write(Math.floor(simpleMath) + lineBreak);
// Assignment operators
// This is a basic single operator assignment
var houseNumber = 1944;
document.write(houseNumber + lineBreak);
// Assignment operators can also do math
var valueOne = 1020;
var valueTwo = 10;
// Redefine a variable using an operator
// options are `+=`, `-=`, `*=`, `/=`
valueOne -= valueTwo;
document.write(valueOne + lineBreak);
</script>
</body>
</html>