Instructions
Create a function ftoc that converts Fahrenheit to Celsius.
The formula is: C = (F - 32) * 5/9
Make sure to return a float value.
Hints:
- Use the formula: (fahrenheit - 32) * 5.0 / 9.0
- Use 5.0 instead of 5 to get float division
- Ruby will automatically return the last expression
Your Code
def ftoc(fahrenheit) (fahrenheit - 32) * 5.0 / 9.0 end
RSpec.describe "ftoc" do
it "converts freezing point" do
expect(ftoc(32)).to eq(0)
end
it "converts boiling point" do
expect(ftoc(212)).to eq(100)
end
it "converts body temperature" do
expect(ftoc(98.6)).to be_within(0.1).of(37)
end
end
Results
Click "Run Tests" to see results