Need help?
Ask a question or report a problem on GitHub.
Open an issue
A complete console program
A small task helper that puts the pieces together: a menu, input, colors, a list, and a loop that runs until you quit.
Otter
say "Task helper" in color "cyan" tasks are empty keepGoing is true while keepGoing actions are "Add a task" "Show tasks" "Quit" . choose from actions into action if action is "Add a task" ask "Task name: " and call it title add title to tasks say "Added:" title in color "green" otherwise if action is "Show tasks" if length of tasks is 0 say "No tasks yet." in color "yellow" otherwise each task in tasks say "-" task . . otherwise keepGoing is false . . say "Goodbye"
Save it as tasks.ot and run otter tasks.ot. Choosing 2, then 1 and typing Write docs, then 2, then 3 prints:
Output
Task helper 1. Add a task 2. Show tasks 3. Quit Choose a number: 2 No tasks yet. 1. Add a task 2. Show tasks 3. Quit Choose a number: 1 Task name: Write docs Added: Write docs 1. Add a task 2. Show tasks 3. Quit Choose a number: 2 - Write docs 1. Add a task 2. Show tasks 3. Quit Choose a number: 3 Goodbye
What to notice
- keepGoing is true and while keepGoing keep the loop going until Quit sets it to false.
- choose from returns the item you picked, so the if compares words, not numbers.
- length of tasks is 0 checks for an empty list.
Challenges
- Add a Remove a task choice using remove title from tasks.
- Show progress with show progress N percent while you count the tasks.
- Save the tasks to a file with write, and read them back at the start.
Console programming Files and folders