This course has been updated! We now recommend you take the Basics of Go course.

Check out a free preview of the full Go for JavaScript Developers course:
The "Modifying Struct Values Exercise" Lesson is part of the full, Go for JavaScript Developers course featured in this preview video. Here's what you'd learn in this lesson:

Students are instructed to modify the existing code to change an existing field on a struct if a condition is met. Brenna gives helpful hints, and also asks students to draw conclusions on why a phenomenon is happening in the code.

Get Unlimited Access Now

Transcript from the "Modifying Struct Values Exercise" Lesson

>> Cool, so we're gonna kind of hang out in the structs.go file. We don't need to create a new one but we're gonna hop in to exercise 6a. And so 6a is going to discuss a little bit about how to modify values of a struct. So far, we've learned how to define them, to read the values and kind of interpolate them in to a function.

[00:00:16] The next step is what we wanna do if you wanna change any of those values in some capacity. So in 6a here, the goal is to work with structs. We're still working in our structs.go file. And let's kind of modify our describeGroup function. Right now, we're just printing out a string, regardless.

[00:00:34] And the space available is always set to true based on whatever is available in that particular instance of the group. But let's modify it, and say we only want to accept new users. If there are fewer than two existing users in the group. It's a really small group.

[00:00:49] You can only ever have two users. So, if there's more than two, you need to modify that space available attribute, to be false. So within the describe group function, you're going to add some logic around, making an if statement, checking that attribute, and then modifying it, if that number is less than or greater than 2.

[00:01:10] There'll be a couple things you notice, a couple of errors that might show up. And some behavior that's gonna be a little strange, which is expected. And we're gonna talk about what that means when we come back.