This commit is contained in:
wagslane
2023-05-01 15:25:27 -06:00
parent f8912668b8
commit 9be3074de6
868 changed files with 58698 additions and 2 deletions

View 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)
}

View File

@@ -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)
}

View File

@@ -0,0 +1 @@
number of seconds in an hour: 3600

View 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.