forked from Zelechos/Pragmatic_JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise29.js
More file actions
31 lines (26 loc) · 1.25 KB
/
Copy pathExercise29.js
File metadata and controls
31 lines (26 loc) · 1.25 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
// 29) Programa una función para convertir grados Celsius a Fahrenheit y viceversa, pe. miFuncion(0,"C") devolverá 32°F.
import validateString, { validateNumber } from "./validations.js"
'use strict'
const gradesTransform = (degrees, thermometric_unit) =>
(validateString(thermometric_unit) && validateNumber(degrees))
? thermometricTransform(degrees, thermometric_unit)
: console.warn(`wrong parameter => parameter{${typeof(degrees)}} , parameter1{${typeof(thermometric_unit)}} \n was expected => parameter{number} , parameter1{string}`);
const thermometricTransform = (degrees, thermometric_unit) =>{
if (thermometric_unit === "C"){
return console.log(`${degrees} grados Celsius son ${(degrees * 9/5) +32} grados Fahrenheit`);
}else if (thermometric_unit === "F"){
return console.log(`${degrees} grados Fahrenheit son ${(degrees - 32)*5/9} grados Celsius`);
}else{
return console.error(`Solo se aceptan las unidades termometricas de {C} y {F} !! No => {${thermometric_unit}}`);
}
}
// Testing
gradesTransform(1 , "C");
gradesTransform(1 , "F");
gradesTransform();
gradesTransform(100 , "5");
gradesTransform(78);
gradesTransform(5 , 5);
gradesTransform(true);
gradesTransform(-100 , "C");
gradesTransform([]);