-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7.4_prac.html
51 lines (50 loc) · 1.4 KB
/
7.4_prac.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
<!DOCTYPE html>
<html>
<head>
<title>distance conversion</title>
</head>
<body>
<script>
function convertToKm(length){
return `${length*1.6} km`;
}
function convertToMiles(length){
return `${length/1.6} Miles`;
}
function convertToFeet(length){
return `${length*5280} ft`;
}
function convertToFoot(length){
return `${length*3281} ft`;
}
function convertLength(length,from,to){
if(from === 'miles' && to === 'km'){
return convertToKm(length);
}
else if(from === 'km' && to === 'miles'){
return convertToMiles(length);
}
else if(from === 'km' && to === 'km'){
return `${length} km`;
}
else if(from === 'miles' && to === 'ft'){
return convertToFeet(length);
}
else if(from === 'km' && to === 'ft'){
return convertToFoot(length);
}
else{
return `Invalid Unit: ${from}`;
}
}
console.log(convertLength(50,'miles','km'));
console.log(convertLength(32,'km','miles'));
console.log(convertLength(50,'km','km'));
console.log('NEXXT');
console.log(convertLength(5,'miles','km'));
console.log(convertLength(5,'miles','ft'));
console.log(convertLength(5,'km','ft'));
console.log(convertLength(5,'lbs','lbs'));
</script>
</body>
</html>