File size: 3,893 Bytes
4656ce2
 
4ea84c9
 
 
 
62a5e30
4ea84c9
 
 
 
62a5e30
4ea84c9
 
 
 
 
 
 
 
62a5e30
4ea84c9
 
 
 
 
 
 
 
62a5e30
4ea84c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4656ce2
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
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html>
<head>
    <title>Length Converter</title>
</head>
<body>
    <h1>Length Converter</h1>

    <label for="input">Meaning:</label>
    <input type="number" id="input" placeholder="Enter value">
<p></p>
    <label for="from">From:</label>
    <select id="from">
        <option value="meter">Meters</option>
        <option value="kilometer">Kilometers</option>
        <option value="millimeter">Millimeters</option></option>
        <option value="decimeter">Decimeters</option>
        <option value="centimeter">Centimeters</option>
    </select>

    <label for="to">To:</label>
    <select id="to">
        <option value="meter">Meters</option>
        <option value="kilometer">Kilometers</option>
        <option value="millimeter">Millimeters</option>
        <option value="decimeter">Decimeters</option>
        <option value="centimeter">Centimeters</option>
    </select>
<p></p>
    <button onclick="convert()">Convert</button>

    <p id="result"></p>

    <script>
        function convert() {
            var input = document.getElementById("input").value;
            var from = document.getElementById("from").value;
            var to = document.getElementById("to").value;

            var result;

            if (from === "meter") {
                if (to === "meter") {
                    result = input;
                } else if (to === "kilometer") {
                    result = input / 1000;
                } else if (to === "millimeter") {
                    result = input * 1000;
                } else if (to === "decimeter") {
                    result = input * 10;
                } else if (to === "centimeter") {
                    result = input * 100;
                }
            } else if (from === "kilometer") {
                if (to === "meter") {
                    result = input * 1000;
                } else if (to === "kilometer") {
                    result = input;
                } else if (to === "millimeter") {
                    result = input * 1000000;
                } else if (to === "decimeter") {
                    result = input * 10000;
                } else if (to === "centimeter") {
                    result = input * 100000;
                }
            } else if (from === "millimeter") {
                if (to === "meter") {
                    result = input / 1000;
                } else if (to === "kilometer") {
                    result = input / 1000000;
                } else if (to === "millimeter") {
                    result = input;
                } else if (to === "decimeter") {
                    result = input / 100;
                } else if (to === "centimeter") {
                    result = input / 10;
                }
            } else if (from === "decimeter") {
                if (to === "meter") {
                    result = input / 10;
                } else if (to === "kilometer") {
                    result = input / 10000;
                } else if (to === "millimeter") {
                    result = input * 100;
                } else if (to === "decimeter") {
                    result = input;
                } else if (to === "centimeter") {
                    result = input * 10;
                }
            } else if (from === "centimeter") {
                if (to === "meter") {
                    result = input / 100;
                } else if (to === "kilometer") {
                    result = input / 100000;
                } else if (to === "millimeter") {
                    result = input * 10;
                } else if (to === "decimeter") {
                    result = input / 10;
                } else if (to === "centimeter") {
                    result = input;
                }
            }

            document.getElementById("result").innerHTML = result;
        }
    </script>
</body>
</html>