Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

So i am just practicing an two problems.

One the response method i created isnt triggering an two on line 46 after dive its telling me its expecting a keyword end? But there is no statements near the puts dive. Heres my syntax:

def adding
  print " choose number "
  num1 = gets.chomp.to_i
  puts" choose what you wanna add " 
  num2 = gets.chomp.to_i
  puts"Now adding: "
return num1 + num2
  end 

def subtract

  print"Choose one number"
  sub = gets.chomp.to_i
  puts " choose what to minus"
  sub2 = gets.chomp.to_i
  puts "Now subtracting:"
  return sub - sub2
  end

def divide 
  print " divide"
  div1 = gets.chomp.to_f
  puts"Divide by "
  div2 = gets.chomp.to_f
  "Dividing: "

  return div1 / div2
  end

def response(add,sub,div)
  if add 
    puts " response to adding "
    elsif sub
    puts "We losing numbers"
   else div
    puts" Going halves "
    end

add = adding
sub = subtract
 dive = divide
  r = response

puts add
puts sub
puts dive

3 Answers

Angela Visnesky
Angela Visnesky
20,927 Points

You are missing an end in your response function. You have an end to the if statement, but not one for the the function itself.

def response(add,sub,div)
    if add 
      puts " response to adding "
    elsif sub
      puts "We losing numbers"
   else div
      puts" Going halves "
    end
end
Angela Visnesky
Angela Visnesky
20,927 Points

Not sure what I did incorrectly for the code snippet. Anyway, add an end to the function and you should be fine.

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

its saying this now tho.... response': wrong number of arguments (0 for 3) (ArgumentError)
from coop.rb:44:in `<main>'

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

its saying this now tho.... response': wrong number of arguments (0 for 3) (ArgumentError)
from coop.rb:44:in `<main>'

Hi, So for your response function it's taking 3 arguments but nothing is being passed in it. You will also want to have the user have some sort of option with the if statement in order to go thru it. Take a look at what I did with your code. I added a case statement for easier use then called the function at the end and it will print what the user wants.

def adding
  print " choose number "
  num1 = gets.chomp.to_i
  puts" choose what you wanna add " 
  num2 = gets.chomp.to_i
  puts"Now adding: "
return num1 + num2
  end 

def subtract

  print"Choose one number"
  sub = gets.chomp.to_i
  puts " choose what to minus"
  sub2 = gets.chomp.to_i
  puts "Now subtracting:"
  return sub - sub2
  end

def divide 
  print " divide"
  div1 = gets.chomp.to_f
  puts"Divide by "
  div2 = gets.chomp.to_f
  "Dividing: "

  return div1 / div2
  end

def response()
  add = adding()#this calls your function and assigns to variable that can be use in this function
sub = subtract()
 div = divide()
 print "choose a type to display (add,sub,div)"#ask for user input
  answer=gets.chomp.downcase#takes in user input
 case answer
   when "add"
    puts " response to adding #{add} "#string int. for variable
 when "sub"
    puts "We losing numbers #{sub}"
  when "div"
    puts" Going halves #{div}"
    end
  end



puts response()#calls response function and prints output to screen

Hope this make sense

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

Hiya melissa, i appreciate the response. So im sort of grasping what your telling me but might i ask. Was this impossible to pull off with arguement's attached? What i was testing was the whole approach to using functions by storing them in variables. Im new to functions so i was seeing how i can store them in variables then interpolate them. What i am aiming for here is to store the response function in a variable like the others them combine both variables to see if the response function triggers an reacts to the others pending on the statements. Am i making any sense? lol sorry i cant speak ruby well yet. ahaha

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

Like if i were to try

puts sub[response] i would want the response to trigger to the designted statement which would be " we are losing numbers"

The beauty of coding is there's various ways to approach and solve problems. In general if you want to write nice clean code you make something a function/method if you find you're repeating it throughout the program. So if you are saying "we are losing numbers" more the once it would make sense to store it in a method and then call that method when needed. If you are only saying it once then printing it to the screen is fine.

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

Lol ugh i am the worst with case statements i dont know why. syntax:

print " Hello there please enter your first name"

puts " if you have the chosen characteristics then we will continue asking questions." name = gets.chomp case name when name.length == 8 puts "thats just the right number of characters" when name <= 8 puts" not enough characters" when name > 8 puts "way to much" else name.to_i puts "fuck you thats not a name" end

Its saying that theres an arguement error of 8 failed strings you know what that means?