Guest User

Untitled

a guest
Dec 7th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. students = ["alex", "alexs", "frank", "nicholas", "petter", "ramiro", "ronald", "samuel", "timothy", "chris", "alexr", "donato", "ali", "enrique", "will", "jeffery", "jorge", "jon", "khristina", "macus"]
  2.  
  3. word = students.sample
  4. right = "_" * word.length
  5. total_chances = 5
  6.  
  7. wrongs = 0
  8.  
  9. while wrongs < 5 do
  10. puts "\n"
  11. puts "Guess which C21 student is this: "
  12. puts " \n"
  13. puts right
  14. guess = gets.chomp
  15. if word.include? guess
  16. puts "\n"
  17. puts "Yeah!"
  18. word.length.times do |c|
  19. if word[c] == guess
  20. right[c] = guess
  21. print right
  22. puts "\n"
  23. end
  24. end
  25. else
  26. wrongs += 1
  27. puts "Sorry! That name does not have #{guess} Try again!"
  28. puts "You have #{total_chances.to_i - wrongs.to_i} left"
  29. end
  30. unless right.include? "_"
  31. break
  32. end
  33. end
Add Comment
Please, Sign In to add comment