--000e0cd171d2fd78720477864a3e
Content-Type: text/plain; charset=ISO-8859-1

>
> using custom methods. I got it to work...but after some lines it'll put
> "nil" on the next line and continue with the program.
>
> ex. after an input
>
> Please enter a number.
> 4
> nil
> Too low. Try again.
> Please enter a number.
> 7
> nil
> Too low. Try again.
>
> or after a generated line
>
> You guessed the secret number in X tries!
> nil
>
> Why is it saying "nil" everywhere and how do I stop it?
>
> My code is below if that helps...
>
>
Your code works correctly, it just prints nil because of the following:

def num_eval(guess, number)
>  if (guess > 100)
>    puts "That's more than 100! Pick a number between 1 and 100!"
>  elsif (guess < 1)
>    puts "That's less than 1! Pick a number between 1 and 100!"
>  elsif (guess > number)
>    puts "Too high! Try again!"
>  elsif (guess < number)
>    puts "Too low! Try again!"
>  end
> end
>
>
That is how your num_eval function is declared. Each of those if statements
prints to the screen, but the print statement itself returns nil. And the if
statement returns whatever the last line in it's scope returns, so the if
statement returns the nil that the print statement returns. And the last
returned value in the function is what the function returns. So the if
statement returns nil, and that goes out of the function as the return
value.

Then, where you actually use the code below:

   guess  ets().chomp().to_i()
>    puts num_eval(guess, number)
>

You can see that you print the value that num_eval returns, which is nil, as
described above.

So, your program works (at least for my 2 trials), but it just prints nil
because num_eval returns nil, and you are printing it's value.

--000e0cd171d2fd78720477864a3e--