Define functions to convert between celsius and fahrenheit.
Create a file called "temperature.js", which does the following:
- Create a new variable
Temperature
, which is an Object with two properties: - toFahrenheit: A Function which takes one argument:
celsius
(a number), calculates the equivalent value in Fahrenheit, and returns the Fahrenheit value. - toCelsius: A Function which takes one argument:
fahrenheit
(a number), calculates the equivalent value in Celsius, and returns the Celsius value.
The formula for converting Celsius to Fahrenheit is: F = C × (9⁄5) + 32
.
The reverse of that is: C = (F - 32) × (5⁄9)
2. Create a new variable tempToday
, and set the value to 82. This is today’s temperature in Fahrenheit.
3. Create a new variable tempInCelsius
, and set its value equal to the Celsius equivalent, rounded to the nearest whole number.
The Celsius equivalent should be calculated by calling the toCelsius
function property on Temperature
, passing it tempToday
. Round the result by using the Math.round()
function.
4. Create a new variable, message
, and set its value equal to a string that is in this form:
“Today’s temperature is °F, which is °C.”
5. Log message
to the console.
- To begin, fork this repository.
- Create a new Cloud9 workspace from your new repository.
- Alternatively, you may clone your new repository to your computer.
- Modify the files and commit changes to complete your solution.
- Push/sync the changes up to GitHub.
- Create a pull request on the original repository to turn in the assignment.
You are also welcome commit, push, and create a pull request before you’ve completed your solution. You can ask questions or request feedback there in your pull request. Just mention @barberboy
in your comments to get my attention.