Week 1 Review & Practice
Review your progress from Week 1 and build a small CLI tool to practice everything you've learned
Learning Objectives
- Review basic Go syntax, variables, and types
- Practice using control structures (if, switch, for)
- Implement logic using functions with multiple returns
- Build a comprehensive "Calculator & Unit Converter" CLI tool
Week 1 Wrap-up
Congratulations! You’ve completed the first week of Go Basics in 30 Days. You’ve gone from “Hello World” to understanding the core syntax that makes Go unique.
What We’ve Covered
- Day 1: Introduction to Go, environment setup, and your first program.
- Day 2: Variables, constants, and basic data types (int, float, string, bool).
- Day 3: Operators (arithmetic, comparison, logical) and expressions.
- Day 4: Conditionals with
if,else if,else, andswitch. - Day 5: The versatile
forloop,break,continue, andrange. - Day 6: Functions, multiple return values, and variadic functions.
Practice Project: The Multi-Tool CLI
To solidify your knowledge, we’re going to build a small command-line tool that performs various calculations and conversions. This project will use everything you’ve learned so far.
Project Requirements
Create a program that:
- Shows a menu of options to the user.
- Accepts user input for choices and values.
- Implements the following features:
- Temperature Converter: Celsius to Fahrenheit and vice versa.
- Basic Calculator: Addition, subtraction, multiplication, and division.
- Grade Calculator: Takes a numeric score and returns a letter grade.
- Leap Year Checker: Determines if a year is a leap year.
- Uses functions for each feature.
- Uses a loop to allow the user to perform multiple operations until they choose to exit.
Implementation Guide
Here’s a starting point for your main.go:
|
|
Tips for Implementation
- Use
fmt.Scan(&variable)to get user input. - For the calculator, return an error if the user tries to divide by zero.
- Use
switchfor the menu and the calculator operations. - Remember to use
float64for temperature and division results.
Self-Check Quiz
Before you move on to Week 2, ask yourself:
- Can I declare variables using both
varand:=? - Do I understand when to use
intvsfloat64vsstring? - Can I write a loop that skips even numbers?
- Do I feel comfortable returning multiple values from a function?
- Can I handle basic user input using
fmt.Scan?
If you answered “Yes” to all, you’re ready for Week 2!
Summary
This week was all about the foundations. While you haven’t seen everything Go has to offer yet, you now have the tools to write basic functional programs.
Next Steps
In Week 2, we’ll dive into Data Structures. We’ll move beyond simple variables and learn about:
- Arrays and Slices (dynamic arrays)
- Maps (key-value pairs)
- Structs (custom data types)
- Pointers (memory addresses)
Complete the final Week 1 review quiz to unlock Week 2!
Quiz
Complete this quiz with a minimum score of 80% to mark Day 7 as complete.
Discussion
Have questions or want to discuss this lesson? Join the conversation below!