We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I'm with a problem with my code, because it works when I run it on VScode, but when I try on HackerRank, it don't works
def convert_temp(temperature,input_scale:,output_scale:'celsius')
if input_scale=='celsius'
if output_scale=='kelvin'
temperature+=273.15
elsif output_scale=='fahrenheit'
temperature=((temperature*9/5)+32).to_f
end
elsif input_scale=='kelvin'
if output_scale=='celsius'
temperature-=273.15
elsif output_scale=='fahrenheit'
temperature=(((temperature-273.15)*9/5)+32).to_f
end
elsif input_scale=='fahrenheit'
if output_scale=='celsius'
temperature = ((temperature-32)*5/9).to_f
elsif output_scale=='kelvin'
temperature =(((temperature-32)*5/9)+273.15).to_f
end
Ruby - Methods - Keyword Arguments
You are viewing a single comment's thread. Return to all comments →
I'm with a problem with my code, because it works when I run it on VScode, but when I try on HackerRank, it don't works
def convert_temp(temperature,input_scale:,output_scale:'celsius') if input_scale=='celsius' if output_scale=='kelvin'
elsif input_scale=='kelvin'
elsif input_scale=='fahrenheit'
end end
puts convert_temp(0, input_scale: 'celsius', output_scale: 'kelvin')