mercredi 23 mars 2016

Ruby - if else statement

I have been working on the configuration an ELSE statement code. here is the code:

puts "Do you like PC?"
case (gets.chomp)
when 'yes'
  puts "I do too"
when 'no'
  puts "Mac is better"
end

Now I am working configure it to (1)use ELSE, and (2) to use ELSEIF. How do I better write this to use "else", and how do I write it to use "elseif". Here is what I wrote for the else version

puts "Do you like PC?"
case (gets.chomp)
if 'yes'
  puts "I do too"
else
  puts "Mac is better"
end

Aucun commentaire:

Enregistrer un commentaire