Advertisement
kremisoski

2 Case / Switch statements

Feb 3rd, 2015
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.80 KB | None | 0 0
  1. /* Two ways of doing the same thing followed by user input example */
  2.  
  3. # Method 1
  4.  
  5. case language
  6. when "JS"
  7.   puts "Websites!"
  8. when "Python"
  9.   puts "Science!"
  10. when "Ruby"
  11.   puts "Web apps!"
  12. else
  13.   puts "I don't know!"
  14. end
  15.  
  16. # Method 2 (don't forget then)
  17.  
  18. case language
  19.   when "JS" then puts "Websites!"
  20.   when "Python" then puts "Science!"
  21.   when "Ruby" then puts "Web apps!"
  22.   else puts "I don't know!"
  23. end
  24.  
  25. # Example
  26.  
  27. puts "Hello there!  What language do you speak?"
  28. language = gets.chomp
  29.  
  30. # Add your case statement below!
  31.  
  32. case language
  33.     when "English" then puts "Hello!"
  34.     when "French" then puts "Bonjour!"
  35.     when "German" then puts "Guten Tag!"
  36.     when "Finnish" then puts "Haloo!"
  37.     when "Spanish" then puts "Hola!"
  38.     else puts "I don't know that language!"
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement