Menu
Coddy logo textTech

Viewing All Tasks

Part of the Logic & Flow section of Coddy's GO journey — lesson 22 of 68.

challenge icon

Challenge

Easy

Continuing with your task management system, you'll now implement the functionality to display all tasks in a user-friendly format. This challenge focuses on iterating through your task collection and presenting each task with its completion status using clear visual indicators.

You will receive two inputs:

  • A string representing the number of tasks (e.g., "4")
  • A string containing task data in the format: "name1:status1,name2:status2,name3:status3" where status is either "true" or "false" (e.g., "Buy groceries:false,Call dentist:true,Finish project:false,Review code:true")

Your task is to:

  1. Define the same Task struct from previous challenges with Name (string) and Completed (bool) fields
  2. Create a function called viewAllTasks that takes a slice of Task structs as a parameter
  3. Inside the viewAllTasks function, iterate through the slice and print each task with the following format:
    • For completed tasks: "[x] [task_name]"
    • For incomplete tasks: "[ ] [task_name]"
  4. Parse the task data from the second input to create your slice of tasks:
    • Split the input by commas to get individual task entries
    • For each entry, split by colon to separate the name and status
    • Convert the status string to a boolean ("true" becomes true, "false" becomes false)
  5. Call your viewAllTasks function with the created slice
  6. After displaying all tasks, print a summary in the format: "Total: [total_count] tasks ([completed_count] completed, [incomplete_count] remaining)"

For example, if you have tasks "Buy groceries:false,Call dentist:true,Finish project:false", your output should show each task with appropriate checkboxes and then display the summary with the total count and completion statistics. This challenge practices slice iteration, conditional formatting with if statements, and provides users with a clear view of their task progress.

Try it yourself

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type Task struct {
	Name      string
	Completed bool
}

func viewAllTasks(tasks []Task) {
	// TODO: Implement the function to display all tasks
	// For completed tasks: "[x] [task_name]"
	// For incomplete tasks: "[ ] [task_name]"
}

func main() {
	var numTasksStr string
	fmt.Scanln(&numTasksStr)
	numTasks, _ := strconv.Atoi(numTasksStr)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	taskData := scanner.Text()

	var tasks []Task

	// TODO: Parse the task data from taskData string
	// Split by commas to get individual task entries
	taskEntries := strings.Split(taskData, ",")
	_ = taskEntries

	// For each entry, split by colon to separate name and status
	// Convert status string to boolean and create Task structs

	// TODO: Call viewAllTasks function with the created slice

	// TODO: Calculate and print summary
	// Format: "Total: [total_count] tasks ([completed_count] completed, [incomplete_count] remaining)"
	_ = tasks
	_ = numTasks
}

All lessons in Logic & Flow