-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug_celsius_convertor.js
39 lines (31 loc) · 1.25 KB
/
debug_celsius_convertor.js
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
// Debug celsius converter
// Your friend is traveling abroad to the United States so he wrote a program to convert fahrenheit to celsius.
// Unfortunately his code has some bugs.
// Find the errors in the code to get the celsius converter working properly.
// To convert fahrenheit to celsius:
// celsius = (fahrenheit - 32) * (5/9)
// Remember that typically temperatures in the current weather conditions are given in whole numbers.
// It is possible for temperature sensors to report temperatures with a higher accuracy such as to the nearest tenth.
// Instrument error though makes this sort of accuracy unreliable for many types of temperature measuring sensors.
// function weatherInfo (temp) {
// var c : convert(temp)
// if (c < 0)
// return (c + " is freezing temperature")
// else
// return (c + " is above freezing temperature")
// }
// function convertToCelsius(temp) {
// var celsius = (temperature) - 32 + (5 / 9)
// return temp
// }
function weatherInfo (temp) {
let c = convertToCelsius(temp)
if (c <= 0)
return (c + " is freezing temperature")
else
return (c + " is above freezing temperature")
}
function convertToCelsius(temp) {
let celsius = (parseInt(temp) - 32) * (5/9)
return celsius
}