Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # "Hello, Ruby!" ((=
- # Getting user's name & greeting them
- puts "Welcome to 'GuessTehNum'"
- print "What's your name? ~ "
- userName = gets.chomp
- puts "Welcome, #{userName}!"
- # Generating a random number for the player to guess
- puts "\nI've got a random number from 1-100, Can you guess it? :D"
- rand = rand(100) + 1
- # Counting user's guesses
- score = 0
- won = false
- while won == false && score < 10
- puts "Let's begin, You have #{10 - score} tries left!"
- print "Make a guess ~ "
- guess = gets.to_i
- score += 1
- # Comparing user's guess with teh randnum and printing appropriate message
- if guess < rand
- puts "Oops, Too Low! :P"
- elsif guess > rand
- puts "Oops, Too High! :P"
- elsif guess == rand
- puts "Good Job, #{userName}!\nYay, You guessed my number in #{score} guesses!"
- won = true
- end
- end
- # Revealing teh number in case user ran out of tries
- unless won
- puts "Sorry, You lost! :D\nPS: My number was #{rand}!"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement