BarbaraWidjono, Edges, calculator.rb#41
Conversation
CalculatorWhat We're Looking For
Good work on this project! The project's code is readable and straightforward and a good solution, which is my favorite kind of solution :) While you didn't get a chance to add in checking that the user input for numbers for validity, I think you still hit all the learning goals-- practicing making methods, working with complex conditionals, etc. If I were to make a major suggestion, it would be to try using a case statement ( Read more here ) I'm adding a few comments, mostly on small formatting suggestions In general, good work on this code :) |
| return (x * y).to_f | ||
| end | ||
|
|
||
| def division (x , y) |
There was a problem hiding this comment.
Even though the code still runs, most style guides, style conventions, and text editors like Atom will complain/give a warning if there's a space between the method name and the parentheses. aka:
def division (x , y)should be this:
def division(x , y)|
|
||
| # Determining which method to invoke depending on the operand chosen by the user | ||
| if operand == "add" || operand == "+" | ||
| puts "Answer: #{first_value} + #{second_value} = #{addittion(first_value, second_value)}" |
There was a problem hiding this comment.
I really like how concise these lines are: You are interpolating things and calling methods in them -- it shows that you understand that many method calls can happen on one line, which is a crucial piece of understanding!
| end | ||
|
|
||
| def subtraction(x, y) | ||
| return (x - y).to_f |
There was a problem hiding this comment.
you end up calling .to_f on this result (and in some other calculation methods).
However, let's establish some things:
- in lines 21 and 26, you get the values for
first_valueandsecond_valueby getting user input and then converting them to floats immediately with.to_f.
And let's remember:
- in Ruby, if you do addition, subtraction, multiplication, or division with any floats, the result will be a float
Therefore: do you need to convert to a float here?
Sometimes, it's good to have a .to_f in here just in case there's a chance you still need to convert it, but within this particular program, you probably wouldn't need to call .to_f here. Not a big deal! Just wanted to call out this redundancy.
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions