In case you get stuck anywhere, don't be afraid to ask the coaches! They are here to help and will gladly explain everything to you!
Take notes during the exercises. Even if you never look at them again, they will help you memorise things!
For these exercises, you will use your editor (Visual Studio Code or similar).
First, create an empty file with a meaningful name for this exercise, for example todo_list.rb
. Note the file extension .rb
! Also remember what folder you saved your file in. It makes sense to create a folder for each lesson of the course.
Then, use cd
in the command line to change to that folder. When you run ls
you should see your file there.
Now you can run your Ruby program with ruby todo_list.rb
in the command line.
Repeat the above steps and remember to save your file in the editor before running it!
We’re building a Todo list program in the command line. We’ll do it step by step. After each step you will have a working program.
Hint: In programming, we use the verb implement a lot, e.g. implement this feature. It just means make it work. Write the code which will make it happen.
Example interaction (user-entered text is bold):
> ruby todo_list.rb
Welcome to the todo list
Please enter your command!
something
> ruby todo_list.rb
Welcome to the todo list
Please enter your command!
quit
Goodbye!
Example interaction (user-entered text is bold):
> ruby todo_list.rb
Welcome to the todo list
Please enter your command!
something
Please enter your command!
test
Please enter your command!
quit
Goodbye!
todos
variable and fill it with some example todos (e.g. "Buy milk", "Finish Rubymonstas exercise"). The user should be able to list all todos with the command "list". Our program now supports two commands: "list" and "quit". It will still ask for new commands if the last command wasn't "quit".
Example interaction (user-entered text is bold):
> ruby todo_list.rb
Welcome to the todo list
Please enter your command!
list
Buy milk
Finish Rubymonstas exercise
Please enter your command!
quit
Goodbye!
Example interaction (user-entered text is bold):
> ruby todo_list.rb
Welcome to the todo list
Please enter your command!
add
What is your todo?
cycle home
Please enter your command!
list
Buy milk
Finish Rubymonstas exercise
cycle home
Please enter your command!
quit
Goodbye!
Example interaction (user-entered text is bold):
> ruby todo_list.rb
Welcome to the todo list
Please enter your command!
list
Buy milk
Finish Rubymonstas exercise
Please enter your command!
done
What todo is done?
Finish Rubymonstas exercise
Please enter your command!
quit
Goodbye!