/
001---celsius-to-fahrenheit.js
46 lines (35 loc) · 1.24 KB
/
001---celsius-to-fahrenheit.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
40
41
42
43
44
45
46
/* Basic Algorithm Scripting: Convert Celsius to Fahrenheit
The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5,
plus 32. You are given a variable celsius representing a temperature in Celsius. Use the
variable fahrenheit already defined and assign it the Fahrenheit temperature equivalent to
the given Celsius temperature. Use the algorithm mentioned above to help convert the Celsius
temperature to Fahrenheit.
*/
// Thoughts
/*
-Objective: Return a Fahrenheit temperature
-You are given the formula (F = C * 9/5 + 32)
-Your input is celsius argument
-fahrenheit variable is given in starter code
-add formula to fahrenheit variable
*/
function convertToF(celsius) {
let fahrenheit = (celsius * 9 / 5) + 32;
return fahrenheit;
}
/* Alternative Solutions
// to shorten it
function convertToF(celsius) {
return celsius * 9/5 + 32;
}
// to shorten via ES6
const convertToF = celsius => celsius * 9/5 + 32;
*/
convertToF(30);
// TESTS
// convertToF(0) should return a number
// convertToF(-30) should return a value of - 22
// convertToF(-10) should return a value of 14
// convertToF(0) should return a value of 32
// convertToF(20) should return a value of 68
// convertToF(30) should return a value of 86