mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-18 19:21:17 +00:00
first
This commit is contained in:
28
course/4-structs/exercises/1-intro/code.go
Normal file
28
course/4-structs/exercises/1-intro/code.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type messageToSend struct {
|
||||
}
|
||||
|
||||
// don't edit below this line
|
||||
|
||||
func test(m messageToSend) {
|
||||
fmt.Printf("Sending message: '%s' to: %v\n", m.message, m.phoneNumber)
|
||||
fmt.Println("====================================")
|
||||
}
|
||||
|
||||
func main() {
|
||||
test(messageToSend{
|
||||
phoneNumber: 148255510981,
|
||||
message: "Thanks for signing up",
|
||||
})
|
||||
test(messageToSend{
|
||||
phoneNumber: 148255510982,
|
||||
message: "Love to have you aboard!",
|
||||
})
|
||||
test(messageToSend{
|
||||
phoneNumber: 148255510983,
|
||||
message: "We're so excited to have you",
|
||||
})
|
||||
}
|
||||
30
course/4-structs/exercises/1-intro/complete.go
Normal file
30
course/4-structs/exercises/1-intro/complete.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type messageToSend struct {
|
||||
phoneNumber int
|
||||
message string
|
||||
}
|
||||
|
||||
// don't edit below this line
|
||||
|
||||
func test(m messageToSend) {
|
||||
fmt.Printf("Sending message: '%s' to: %v\n", m.message, m.phoneNumber)
|
||||
fmt.Println("====================================")
|
||||
}
|
||||
|
||||
func main() {
|
||||
test(messageToSend{
|
||||
phoneNumber: 148255510981,
|
||||
message: "Thanks for signing up",
|
||||
})
|
||||
test(messageToSend{
|
||||
phoneNumber: 148255510982,
|
||||
message: "Love to have you aboard!",
|
||||
})
|
||||
test(messageToSend{
|
||||
phoneNumber: 148255510983,
|
||||
message: "We're so excited to have you",
|
||||
})
|
||||
}
|
||||
6
course/4-structs/exercises/1-intro/expected.txt
Normal file
6
course/4-structs/exercises/1-intro/expected.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
Sending message: 'Thanks for signing up' to: 148255510981
|
||||
====================================
|
||||
Sending message: 'Love to have you aboard!' to: 148255510982
|
||||
====================================
|
||||
Sending message: 'We're so excited to have you' to: 148255510983
|
||||
====================================
|
||||
23
course/4-structs/exercises/1-intro/readme.md
Normal file
23
course/4-structs/exercises/1-intro/readme.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# Structs in Go
|
||||
|
||||
We use structs in Go to represent structured data. It's often convenient to group different types of variables together. For example, if we want to represent a car we could do the following:
|
||||
|
||||
```go
|
||||
type car struct {
|
||||
Make string
|
||||
Model string
|
||||
Height int
|
||||
Width int
|
||||
}
|
||||
```
|
||||
|
||||
This creates a new struct type called `car`. All cars have a `Make`, `Model`, `Height` and `Width`.
|
||||
|
||||
In Go, you will often use a struct to represent information that you would have used a dictionary for in Python, or an object literal for in JavaScript.
|
||||
|
||||
## Assignment
|
||||
|
||||
Complete the `messageToSend` struct definition. It needs two fields:
|
||||
|
||||
* `phoneNumber` - an integer
|
||||
* `message` - a string.
|
||||
Reference in New Issue
Block a user