Question: Using function expression, write a JavaScript function (name it: convertCF) convert temperatures between Celcius and Farenheit. this function takes two parameters (val, cf), where val
Using function expression, write a JavaScript function (name it: convertCF) convert temperatures between Celcius and Farenheit.
this function takes two parameters (val, cf), where val is the value you need to convert. This function does not return any result. (1) if val is not a number, your function displays, "I need a number".
terminate the program. (2) if cf is not "C" or "F", your function displays "I am confused :("
terminate the program. (3) if cf is "C", val is the value in Celcius, your function will convert it to Farenheit degree, and display:
(val)C is equivalent to (the result from your calculation)F. e.g., call function convertCF(0, C), it displays:
0C is equivalent to 32F.
4) if cf is "F", val is the value in Farenheit, your function will convert it to Celcius degree, and display: (val)F is equivalent to (the result from your calculation)C.
e.g., call function convertCF(122, F), it displays:
122F is equivalent to 50C. (5) test (call) your function with the example input (parameters):
(0, C) (32, F) (122, F)
*/
Test with the following statements. The corresponding result follows. console.log("/***************************** Task2 *************************/");convertCF("avc", "F"); convertCF("32", "M");
convertCF(32, 'F'); convertCF(0, "C"); convertCF(122, "F");
Sample result for the above function calls: /***************************** Task2 *************************/ I need a number. I am confused :( 32F is equivalent to 0C 0C is equivalent to 32F 122F is equivalent to 50C
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
