Placeholder Upcase

Hi,

Im new to programming in general an new to ruby as well. So please
excuse
my trivial question.

I’m working through a tutorial and encountered a problem with the
“while” loops.

Heres the code:
print “Hallo”
puts""

answer =""
while answer !="".upcase
puts “WAS ICH KANN DICH NICHT HOEREN!”
answer = gets.chomp
end
puts “Nicht seit 1938”

What I want the program to do is to answer every input which is not
written upcase (for example: RUHE) with the line: WAS ICH KANN DICH
NICHT HOEREN?

If the input (any input) is done upcase the answer shall be:
“Nicht seit 1909”

i guess the problem lies somewhere in line 2 --> ="".upcase , but I dont
know how to define that otherwise.

As I see it at the moment line to is saying
while answer IS NOT any upcase input
put …

Am I wrong ?

Would be glad if someone could help, thanks

What I want the program to do is to answer every input which is not
written upcase

check if all string is not upcase : answer.upcase != answer
check if all string is downcase : answer.downcase==answer

or, more precisely :
answer =~ /[a-z\s]+/

Thanks a lot

I have one more question.
If I want the program to only give a specific answer if the user input
is 4 times the same, for example

answer = gets.chomp
while answer != “Hello” *4
puts “Excuse me?”
answer = gets.chomp
end
puts “Oh sure”

The *4 multiplikation doesnt work as i expected. If I write the answer:
Hello Hello Hello Hello

it will still stay in the loop.

Ben Burk wrote in post #1147238:

The *4 multiplikation doesnt work as i expected. If I write the answer:
Hello Hello Hello Hello

Use irb for test ruby code :

[email protected]:~$ irb
irb(main):001:0> “hello”*4
=> “hellohellohellohello”
irb(main):002:0> “Hello”*4
=> “HelloHelloHelloHello”
irb(main):003:0> "Hello "*4
=> "Hello Hello Hello Hello "
irb(main):004:0> "Hello "*4 == “Hello Hello Hello Hello”
=> false
irb(main):005:0> "Hello "*4 == "Hello Hello Hello Hello "
=> true
irb(main):006:0> exit
[email protected]:~$

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs