DEV Community

Cover image for Find The Number
Thomas Bnt ☕
Thomas Bnt ☕

Posted on • Updated on

Find The Number

Find The Number

Hello ! The code and the post show my first script in Ruby, please be indulgent.

  • Description

It is a basic 'game' under console/terminal that must be run with ruby.
The goal? Find the exact number.

  • The system

A simple random number for the chances and a condition to check whether it is small or big. If he is too big or too small, he will mark it for you.

Example of the script

  • Code
MaxChiffre = 20
NumberToGuess =
MaxChance =
a = nil
puts "Enter your number between 0 and #{MaxChiffre} included, you only have #{MaxChance} chances."
for num in 1..MaxChance
  next if a == NumberToGuess
  a = gets.chomp.to_i
  if a > NumberToGuess
    puts "Number too big"
  elsif a < NumberToGuess
    puts "Number too small"
puts "Congratulations, you've found it !" if a == NumberToGuess
puts "Pity ! It was #{NumberToGuess}. " if a != NumberToGuess
Enter fullscreen mode Exit fullscreen mode
  • GitHub

The repository is on GitHub, check out now.

GitHub logo thomasbnt / Find-The-Number

My first script in Ruby.

Top comments (6)

anbrandt profile image
Andrzej Brandt

nice one. however, I would strongly recommend checking the styling guide for Ruby - In the code example, you are using uppercase letters in naming variables - a practice that is foreign in Ruby.

thomasbnt profile image
Thomas Bnt ☕

oh yes I know, I had just made the code with capital letters to better find me. 😁

peter profile image
Peter Kim Frank

Good use of a GIF to show the gameplay :)

thomasbnt profile image
Thomas Bnt ☕

Yeah, it seems easier to show this game 👌

nektro profile image
Meghan (she/her)


thomasbnt profile image
Thomas Bnt ☕

Thank you ! ☺️