How to solve these coding exercises:


Coding Exercise #1

1. Create your own struct type called person that stores the following data: name, age and a list with favorite colors.

2. Declare and initialize two values of type person, one called me and another called you.

3. Print out the struct values.

Are you stuck? Do you want to see the solution for this exercise? Click here.


Coding Exercise #2

Consider the code from the previous exercise and:

1. Change the name or the struct value called me to "Andrei"

2. Take in a new variable the favorites colors of struct value called you. Print out the type and the value of the new variable.

3. Add a new favorite color to the second struct value called you.

4. Print out the struct values.

Are you stuck? Do you want to see the solution for this exercise? Click here.


Coding Exercise #3

Consider the code from Exercise #1.

Iterate and print out the favorite colors of the struct value called me.

Are you stuck? Do you want to see the solution for this exercise? Click here.


Coding Exercise #4

Change the code from Exercise #1 and:

1. Create a new struct type called grades with  2 fields: grade and course

2. Add another field of type grades to person struct type (embedded struct).

3. Change the initialization of the struct values called me and you to contain information about the grades.

4. Change the grade and the course of one struct value to "Golang" and 98.

5. Print out the struct values.

Are you stuck? Do you want to see the solution for this exercise? Click here.