Conversation
CalculatorWhat We're Looking For
Well done on this project Steph! You did a great job practicing some interesting syntax we've learned, as well as working with the user input. If you had more time on this, I would encourage you to find ways to refactor the Overall, good work! |
| puts "3. mulitply(*)" | ||
| puts "4. divide(/)" | ||
|
|
||
| # Ask user to describe what operation performed. YOu will have to build in a feature that |
There was a problem hiding this comment.
Fantastic comments to describe what is going on right now :)
| puts "Please enter a correct operation" | ||
| user_choice = gets.chomp | ||
| end | ||
| end |
There was a problem hiding this comment.
I like your strategy of using choice here in this while loop! It looks like choice will always be a boolean, and it will be false if the operator is invalid, and true if it is valid and successful. Here, you use a while loop AND an if/else statement. Could we use the while loops condition and the if condition, and consider combining them? Consider something like:
while !operations.include?(user_choice)
puts "Please enter a correct operation"
user_choice = gets.chomp
endThis is saying "while the operations array does NOT include the value of user_choice, then that means that the user_choice is not valid, and so we ask for more user input. If the operations array DID include user_choice, then it was valid, and the computer will move past this code"
| print "What is your first number: " | ||
| begin | ||
| num_one = gets.chomp | ||
| num_one= Integer(num_one) |
There was a problem hiding this comment.
This is such a small detail, but I really like having spaces around my =, so num_one = Integer(num_one)
| rescue ArgumentError | ||
| print "Please enter a number:" | ||
| retry | ||
| end |
There was a problem hiding this comment.
We'll learn so much more about begin ... rescue clauses later in the program! I think it's okay to use begin ... rescue clauses right now if you'd like, but I could imagine this code being refactored into a while loop if you also refactored some logic
| print "Please enter a number:" | ||
| retry | ||
| end | ||
| print num_one |
There was a problem hiding this comment.
Because you print num_one here, it ends up looking awkward in the terminal, because num_one gets displayed even though I (the user) just typed it! Maybe we can get rid of this line?
| print "Please enter a number:" | ||
| retry | ||
| end | ||
| print num_two |
There was a problem hiding this comment.
Watch your indentation here! It looks like your indentation got off-- rescue and end should not be indented
| print "Please enter a number:" | ||
| retry | ||
| end | ||
| print num_two |
There was a problem hiding this comment.
Same as above about print num_two here: Because you print num_two here, it looks awkward in the terminal, because num_two gets displayed even though I (the user) just typed it! Maybe we can get rid of this line?
| when "divide", "/" | ||
| solution = (num_one/num_two).to_f | ||
| puts "#{solution}" | ||
| end |
There was a problem hiding this comment.
Nicely done on the case statement!
Calculator
Congratulations! You're submitting your assignment.
Comprehension Questions