File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Help user find degF or degC based on their Conversion Selection. Use
3
+ Case Statement and ensure that the inputs are within the Freezing Point (
4
+ 0 °C / 32 °F ) and the Boiling Point of Water ( 100 °C / 212 °F )
5
+ a. degF = (degC * 9/5) + 32
6
+ b. degC = (degF – 32) * 5/9
7
+ */
8
+
9
+ /*
10
+ Function to convert degC to degF
11
+ */
12
+ let degC_To_DegF = function ( degC ) {
13
+ return degF = ( degC * 9 / 5 ) + 32 ;
14
+ }
15
+
16
+ /*
17
+ Function to convert degF to degC
18
+ */
19
+ let degF_to_DegC = function ( degF ) {
20
+ return degC = ( degF - 32 ) * ( 5 / 9 ) ;
21
+ }
22
+
23
+ /*
24
+ Main code for temperature conversion
25
+ */
26
+ const prompt = require ( 'prompt-sync' ) ( ) ;
27
+ console . log ( ) ;
28
+ let selection = parseInt ( prompt ( " Enter what your want to do => 1) degC to degF , 2) degF to degC => " ) ) ;
29
+ switch ( selection ) {
30
+ case 1 :
31
+ let degC = prompt ( " Enter temprature -> " ) ;
32
+ if ( 0 <= degC && degC <= 100 ) {
33
+ console . log ( " " + degC + " degC = " + degC_To_DegF ( degC ) + " degF \n" ) ;
34
+ } else {
35
+ console . log ( " Invalid Temperature \n" )
36
+ }
37
+ break ;
38
+ case 2 :
39
+ let degF = prompt ( " Enter temprature -> " ) ;
40
+ if ( 32 <= degF && degF <= 212 ) {
41
+ console . log ( " " + degF + " degF = " + degF_to_DegC ( degF ) + " degC \n" ) ;
42
+ } else {
43
+ console . log ( " Invalid Temperature \n" )
44
+ }
45
+ break ;
46
+ default :
47
+ console . log ( " Invalid Input \n" )
48
+ }
You can’t perform that action at this time.
0 commit comments