+ 2

Ruby Question

Hi, I'm trying to make a simple program in Ruby for my civics class, it's written like this: puts "What conflict would you like to cover?" myVar = gets.chomp if myVar = "North Korea" puts "You have chosen North Korea" if myVar = "Syria" puts "You have chosen Syria" end end The purpose is, if a person enters North Korea or Syria in the user input box, the console prints "You have chosen (conflict)", I want to develop it further and add some more scenarios later, but right now, I'm getting the following error from the console: ..\Playground\:6: warning: found = in conditional, should be == ..\Playground\:4: warning: found = in conditional, should be == So I assumed I was supposed to change the = to ==, which just didn't leave any result other than the "What conflict would you like to cover?". I'm confused at what to do, how do I make the code correct and that it prints "You have chosen (conflict)" based on user input? Thanks in advance

9th Mar 2018, 8:56 AM
CW Gillberg
CW Gillberg - avatar
4 Respuestas
+ 10
Here is the edited example of your code. https://code.sololearn.com/cKjDy871VdlU/?ref=app
9th Mar 2018, 9:00 AM
Nikhil
Nikhil - avatar
+ 2
Oh, thanks. I see what I did now, appreciate the fast responses!
9th Mar 2018, 9:14 AM
Carl-William Gillberg
Carl-William Gillberg - avatar
+ 2
I would suggest you another thing. Add to your variable myVar a downcase method before comparing and then compare to 'north korea' or 'syria'. That way you will cover people inserting all the manners it could be inserted, like: North Korea NORTH KOREA north korea NoRtH KoReA ans so on... it would be something like if myVar.downcase == 'north korea'
9th Mar 2018, 12:19 PM
Pietro Majowka
Pietro Majowka - avatar
0
I want an example of Ruby
6th Jun 2021, 12:08 AM
حسين شكر فتحي المولى
حسين شكر فتحي المولى - avatar