mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-14 09:11:16 +00:00
first
This commit is contained in:
12
course/2-variables/exercises/8-computed_constants/code.go
Normal file
12
course/2-variables/exercises/8-computed_constants/code.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
const secondsInMinute = 60
|
||||
const minutesInHour = 60
|
||||
const secondsInHour = // ?
|
||||
|
||||
// don't edit below this line
|
||||
fmt.Println("number of seconds in an hour:", secondsInHour)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
const secondsInMinute = 60
|
||||
const minutesInHour = 60
|
||||
const secondsInHour = secondsInMinute * minutesInHour
|
||||
|
||||
// don't edit below this line
|
||||
fmt.Println("number of seconds in an hour:", secondsInHour)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
number of seconds in an hour: 3600
|
||||
25
course/2-variables/exercises/8-computed_constants/readme.md
Normal file
25
course/2-variables/exercises/8-computed_constants/readme.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Computed Constants
|
||||
|
||||
Constants must be known at compile time. More often than not they will be declared with a static value:
|
||||
|
||||
```go
|
||||
const myInt = 15
|
||||
```
|
||||
|
||||
However, constants *can be computed* so long as the computation can happen at *compile time*.
|
||||
|
||||
For example, this is valid:
|
||||
|
||||
```go
|
||||
const firstName = "Lane"
|
||||
const lastName = "Wagner"
|
||||
const fullName = firstName + " " + lastName
|
||||
```
|
||||
|
||||
That said, you *cannot* declare a constant that can only be computed at run-time.
|
||||
|
||||
## Assignment
|
||||
|
||||
Keeping track of time in a message-sending application is *critical*. Imagine getting an appointment reminder an hour **after** your doctor's visit.
|
||||
|
||||
Complete the code using a computed constant to print the number of seconds in an hour.
|
||||
Reference in New Issue
Block a user