-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp_converter.html
46 lines (44 loc) · 1.63 KB
/
temp_converter.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
<!DOCTYPE html>
<html>
<head>
<script>
const calculateTemp = () =>{
const val = document.getElementById('temp').value;
const type = document.getElementById('temp_diff').value;
// console.log(type);
const celTofar = (celsius) =>{
let fahrenhite = Math.round((celsius * 9/5)+ 32);
return fahrenhite;
}
const fartoCel = (fahrenhite) =>{
let cel = Math.round((fahrenhite -32)* 5/9);
return cel;
}
let result;
if(type =='cel'){
console.log('hello');
result = celTofar(val);
document.getElementById('result_container').innerHTML = `= ${result}farhenhite`;
}
else{
result = fartoCel(val);
document.getElementById('result_container').innerHTML = `= ${result}Celsius`;
}
}
</script>
</head>
<body>
<form id='tempCal' onsubmit="calculateTemp(); return false">
<label> Please Input the temperature you'd lke to convert</label>
<input type='number' name='temp' id='temp'>
<!-- </br> -->
<select name='temp_diff' id='temp_diff'>
<option value="cel">Celsius</option>
<option value="far">Fahrenhite</option>
</select>
</br>
<input type="submit" name='temp'>
<span id='result_container'></span>
</form>
</body>
</html>