Created
February 5, 2021 21:55
-
-
Save manavm1990/950b5bfd1772654f60d0018817e1c651 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* When I click and start typing in either input, | |
* update the other's input value with the converted temperature. | |
* | |
* HINTS: 1. 'keyup' event | |
* 2. Use function keyword so that you can use 'this' | |
*/ |
This file contains hidden or 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
const converters = { | |
toCelsius(fahrenheit) { | |
return ((fahrenheit - 32) * 5) / 9 | |
}, | |
toFahrenheit(celsius) { | |
return (celsius * 9) / 5 + 32 | |
}, | |
} | |
export default (temperature, conversion) => { | |
const parsedTemp = parseFloat(temperature) | |
if (Number.isNaN(parsedTemp)) { | |
return "Not something we can convert! 😞" | |
} | |
return Math.round(converters[conversion](parsedTemp) * 1000) / 1000 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment