-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction3.html
More file actions
38 lines (36 loc) · 1.27 KB
/
Copy pathfunction3.html
File metadata and controls
38 lines (36 loc) · 1.27 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function convertLength(lenght, from, to){
if(from === 'miles' && to === 'km')
newLenght = `${(lenght * 1.6)} km`;
else if(from === 'km' && to === 'miles')
newLenght = `${(lenght / 1.6)} miles`;
else if(from === 'miles' && to === 'ft')
newLenght = `${(lenght * 5280)} ft`;
else if(from === 'ft' && to === 'miles')
newLenght = `${(lenght / 5280)} miles `;
else if(from === 'km' && to === 'ft')
newLenght = `${(lenght * 3281)} ft`;
else if(from === 'lbs' && to === 'lbs')
newLenght =`invalid unit: ${from}`;
else if(from === to)
newLenght = `${(lenght)} ${from}`;
console.log(newLenght)
}
convertLength(50, 'miles', 'km');
convertLength(32, 'km', 'miles');
convertLength(30, 'km', 'km');
convertLength(5, 'miles', 'km')
convertLength(5, 'miles', 'ft')
convertLength(5, 'km', 'ft')
convertLength(5, 'lbs', 'lbs');
</script>
</body>
</html>