-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.js
96 lines (94 loc) · 3.49 KB
/
base.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var num = document.getElementById('num');
var frombase = document.getElementById('frombase');
var tobase = document.getElementById('tobase');
var result = document.getElementById('result');
var form = document.getElementById('base');
form.addEventListener('submit', function(event){
if( !num.value || !frombase.value || !tobase.value )
{
alert("Please fill in all the fields");
}
else if( (frombase.value === "10" || frombase.value === "2" || frombase.value === "8" || frombase.value === "16") && (tobase.value === "10" || tobase.value === "2" || tobase.value === "8" || tobase.value === "16"))
{
if( frombase.value === "10" && tobase.value === "2")
{
var n = parseInt(num.value , 10).toString(2);
result.innerText = "Result: " + n;
event.preventDefault();
}
if( frombase.value === "10" && tobase.value === "8")
{
var n = parseInt(num.value , 10).toString(8);
result.innerText = "Result: " + n;
event.preventDefault();
}
if( frombase.value === "10" && tobase.value === "16")
{
var n = parseInt(num.value , 10).toString(16);
result.innerText = "Result: " + n;
event.preventDefault();
}
if( frombase.value === "2" && tobase.value === "10")
{
var n = parseInt(num.value , 2);
result.innerText = "Result: " + n;
event.preventDefault();
}
if( frombase.value === "2" && tobase.value === "8")
{
var n = parseInt(num.value , 2).toString(8);
result.innerText = "Result: " + n;
event.preventDefault();
}
if( frombase.value === "2" && tobase.value === "16")
{
var n = parseInt(num.value , 2).toString(16);
result.innerText = "Result: " + n;
event.preventDefault();
}
if( frombase.value === "8" && tobase.value === "10")
{
var n = parseInt(num.value , 8);
result.innerText = "Result: " + n;
event.preventDefault();
}
if( frombase.value === "8" && tobase.value === "2")
{
var n = parseInt(num.value , 8).toString(2);
result.innerText = "Result: " + n;
event.preventDefault();
}
if( frombase.value === "8" && tobase.value === "16")
{
var n = parseInt(num.value , 8).toString(16);
result.innerText = "Result: " + n;
event.preventDefault();
}
if( frombase.value === "16" && tobase.value === "10")
{
var n = parseInt(num.value , 16);
result.innerText = "Result: " + n;
event.preventDefault();
}
if( frombase.value === "16" && tobase.value === "2")
{
var n = parseInt(num.value , 16).toString(2);
result.innerText = "Result: " + n;
event.preventDefault();
}
if( frombase.value === "16" && tobase.value === "8")
{
var n = parseInt(num.value , 16).toString(8);
result.innerText = "Result: " + n;
event.preventDefault();
}
if( frombase.value === tobase.value)
{
alert("Aise kaise challega didi. Conversion ki zaroorat hi nahi. Result " + num.value + " hi hoga.");
}
}
else
{
alert("Are bhai bhai bhai bhai, input shai de do. Binary, Hexadecimal, Octal aur Decimal hi challega");
}
});