Before gettign started, you'll need a few tools to work with user input and output.
- How do we tell Ruby to print text to the screen?
- How do we tell Ruby to bring in text from the user?
Write a simple Ruby program which prompts the user to enter a message, then prints that message to the terminal. For example:
Type your message:
(user types "pizza" and presses enter)
pizza
Extend your previous program so that if the text the user enters has an even number of letters, it prints "EVEN!", and if it has an odd number of letters, it prints "ODD!".
Write a new program that prompts the user for a message, then, depending on the following conditions, prints an appropriate message:
- If the message ends with a consonant, print "CONSONANT!"
- If the message ends with a vowel, print "VOWEL!"
- If the message ends with a "y", print "DON'T KNOW!"
Use a times
loop to generate this output:
Line
Line
Line
Line
Line
Build on your answer from the problem above and add an if
/else
to generate output like this:
Line is even
Line is odd
Line is even
Line is odd
Line is even
Generate the output below using three totally separate implementations (times
, while
and until
):
This is my output line 1
This is my output line 2
This is my output line 3
This is my output line 4
This is my output line 5
Write two implementations, one with while
and one with until
that output the following:
(The secret number is 8)
Guess is 4
Guess again!
Guess is 5
Guess again!
Guess is 9
Guess again!
Guess is 4
Guess again!
Guess is 8
You win!
The secret number and the guesses are both random numbers 0 through 10.