-
Notifications
You must be signed in to change notification settings - Fork 1
/
number.html
52 lines (52 loc) · 1.22 KB
/
number.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>
<title>
sign() function in JavaScript
</title>
<style>
.results {
border : green 1px solid;
background-color : aliceblue;
text-align : left;
padding-left : 20px;
height : 200px;
width : 95%;
}
.resultText {
font-size : 20px;
font-style : normal;
color : blue;
}
</style>
</head>
<body>
<div class = "results">
<h2> Enter the Number </h2>
Number: <input type = "number" name = "number" id = "number" required>
<button type = "button" onclick = "checkForSign()" > Submit </button>
<div class = "resultText">
<p id = "signResult"> </p>
<p id = "result"> </p>
</div>
</div>
</div>
<script type = "text/javascript">
function checkForSign() {
num = document.getElementById("number").value;
if(num == '') {
document.getElementById("result").style.color = "red";
document.getElementById("result").innerHTML = "Please Enter a Valid Number ";
return;
}
var signResult = Math.sign( num );
document.getElementById("result").innerHTML = '';
document.getElementById("signResult").innerHTML = "Math.sign( " + num + " ) returned: " + signResult;
if(signResult == 1) {
document.getElementById("result").style.color = "blue";
document.getElementById("result").innerHTML = "The " + num + " is a positive Number";
}
}
</script>
</body>
</html>