Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ruby
puts("What do you call a girl whose tongue is out all the time!")
what = gets


while what != 'miley'

  puts("Try again! Think and twerk!")
 
  what = gets
end

puts(what.chomp+ ". Wow, you have no life".chomp)
Posted
Updated 27-May-15 15:20pm
v5
Comments
Mohibur Rashid 27-May-15 22:24pm    
So, What happens?
Brisingr Aerowing 27-May-15 22:48pm    
I tried it and it doesn't stop. I am trying lowercasing the input string and comparing it with String.casecmp.
Jenina Kyle 28-May-15 13:52pm    
When the 'what' value is equal to the input value the program should see it as false and end the program. While the user does not input 'miley' it should not stop because the code says 'while what is not equal to miley' it should keep on printing 'try again and twerk!' but what's happening is even if you input the word miley (and make it false so the program can end) is it keep on going on forever.

1 solution

Ruby
puts("What do you call a girl whose tongue is out all the time!")
what = gets.chomp

while what != "miley"

  puts("Try again! Think and twerk!")

  what = gets.chomp
end

puts(what.chomp+ ". Wow, you have no life".chomp)


The input had a new line at the end. The chomp method will get rid of it.

When in doubt, use String#dump[^] to make sure you are getting what you think you are getting.
 
Share this answer
 
v2
Comments
Jenina Kyle 28-May-15 13:52pm    
I tried it but when you input a wrong word at first attempt and when you input 'miley' on the second attempt it still responded with 'try again and twerk!'. When the 'what' value is equal to the input value the program should see it as false and end the program. While the user does not input 'miley' it should not stop because the code says 'while what is not equal to miley' it should keep on printing 'try again and twerk!' but what's happening is even if you input the word miley (and make it false so the program can end) is it keep on going on forever.
Brisingr Aerowing 28-May-15 17:17pm    
Oh yeah. Forgot the second gets. Just change both gets to gets.chomp, and remove the what = what.chomp line (the bold one)
Brisingr Aerowing 28-May-15 18:31pm    
Try it now

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900