Created
February 12, 2020 21:34
-
-
Save willwalker753/16c71643d68042381544744f0e1437f4 to your computer and use it in GitHub Desktop.
Temperature conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function celsToFahr(celsTemp) { | |
let fahrenheit = (celsTemp * 9/5) + 32; | |
return fahrenheit; | |
} | |
function fahrToCels(fahrTemp) { | |
let celsius = (fahrTemp - 32)*(5/9); | |
return celsius; | |
} | |
let celsTemp = 100; | |
console.log(celsToFahr(celsTemp)); | |
let fahrTemp = 32; | |
console.log(fahrToCels(fahrTemp)); | |
function testConversion(fn, input, expected) { | |
if (fn(input) === expected) { | |
console.log('SUCCESS: `' + fn.name + '` is working'); | |
return true; | |
} else { | |
console.log('FAILURE: `' + fn.name + '` is not working'); | |
return false; | |
} | |
} | |
function testConverters() { | |
let cel2FahrInput = 100; | |
let cel2FahrExpect = 212; | |
let fahr2CelInput = 32; | |
let fahr2CelExpect = 0; | |
if ( | |
testConversion(celsToFahr, cel2FahrInput, cel2FahrExpect) && | |
testConversion(fahrToCels, fahr2CelInput, fahr2CelExpect) | |
) { | |
console.log('SUCCESS: All tests passing'); | |
} else { | |
console.log('FAILURE: Some tests are failing'); | |
} | |
} | |
testConverters(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment