-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunit-converter.js
More file actions
67 lines (56 loc) · 1.81 KB
/
unit-converter.js
File metadata and controls
67 lines (56 loc) · 1.81 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
56
57
58
59
60
61
62
63
64
65
66
67
// inch to feet ------------------------
// 12 inch = 1 feet
function inch_to_feet(inch) {
let feet = inch / 12;
return feet;
}
let height = inch_to_feet (65);
console.log(height);
// second way
function inch_to_feet_2 (inch) {
let feet_fraction = inch / 12;
let feet_number = parseInt(feet_fraction);
let inch_remaining = inch % 12;
let result = feet_number + "ft " + inch_remaining + "inch";
return result;
}
let height_2 = inch_to_feet_2(74);
console.log(height_2);
// feet to inch ------------------------
// 1 feet = 12 inch
function feet_to_inch(feet, inch) {
let result = feet * 12 + inch;
return result + " inch";
}
let height_3 = feet_to_inch (6, 2);
console.log(height_3);
// kilometer to miles ---------------------
// 1 km = 0.62137119 miles
function km_to_miles(km) {
let miles = km * 0.62137119;
return miles + " miles";
}
let km = km_to_miles (10);
console.log(km);
// miles to kilometer --------------------
// 1 miles = 1.609344 km
function miles_to_km(miles) {
let km = miles * 1.609344;
return km;
}
let miles = miles_to_km (20);
console.log(miles);
// centimeter to inch ---------------------
// inch to centimeter ---------------------
// centimeter to millimeter ----------------
// millimeter to centimeter ----------------
// kilogram to gram ----------------------
// gram to kilogram ----------------------
// milligram to gram ---------------------
// gram to milligram ---------------------
// kilogram to pound ---------------------
// pound to kilogram ---------------------
// kilogram to milligram ------------------
// milligram to kilogram ------------------
// celsius to fahrenheit -------------------
// fahrenheit to celsius -------------------