Skip to content

Conversation

@CarlyReiter
Copy link

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
Describe how you stored user input in your program? I stored them in variables.
How did you determine what operation to perform? Depending on the user input of either the mathematical symbol or the words the inputted. Example, if they inputted "+" or "add", the add method was called using the variables number_1 and number_2 as parameters.
Do you feel like you used consistent indentation throughout your code? Yes. I worked on that during JSL quite a bit.
If you had more time, what would you have added to or changed about the program? I would have experimented with iterating through the mathematical operations using methods and/or hashes at the end.

@tildeee
Copy link
Collaborator

tildeee commented Aug 12, 2018

Calculator

What We're Looking For

Feature Feedback
Takes in two numbers and an operator and performs the mathematical operation. x
Readable code with consistent indentation. x

HAHAHAHA CARLY! First of all: I didn't preview the code before I ran it, and I was so surprised that I laughed out loud after I had to wait for the calculation to show up. It was incredibly suspenseful

That being said...
Good work on this project!

The code looks pretty good. It works well and the solution is pretty clear. I think largely it's readable and easily understood, not over-complicated.

If I were to call out one thing, it would be about your calculation methods:

you end up defining your methods inside of your case statement. While this totally works, it's convention to pull out all method definitions into the top most level, so they're not inside any case statements or if statements or loops or what have you.

Lastly, you had some questions about organization. If I may make a suggestion...:

Your code, as is, is broken up into three parts roughly:

  1. Getting the operator input, and making the value of the operator value be some string
  2. Getting the number inputs for number_1 and number_2, and then, based on the operator, confirming to the user the two numbers, appropriate to the operator
  3. based on the operator, performing the correct calculation

In parts 2 and 3 in your code, you are doing logic based on an operator ... In part 2, you're using an if/elsif/else on checking what operator is equal to, and in part 3, you're using a case statement to check what operator is equal to.

Even though it would take some reconsidering of the order of some other parts, if you wanted to re-organize and combine those two checks, I would recommend thinking about that aspect first!

Overall, the code is good :) I have a couple of other minor comments, but nothing big. Good work!

# Calculations. Certainly not DRY... at least not yet. Can loop through a Method or Hash? Or Method inside a Method or Mathod using a Hash?
case operator
when "multiply"
def multiply (first, second)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 multiply (first, second)

should be this:

def multiply(first, second)

want_explanation = gets.chomp.downcase
if want_explanation == "yes" || want_explanation == "sure"
explanation
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just me being nitpicky-- this if ... end block is indented one indent too much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants