fix: constants and if code and quizzes

This commit is contained in:
Inanc Gumus
2018-11-11 15:59:28 +03:00
parent b267671da1
commit 95be6d2d3c
3 changed files with 21 additions and 21 deletions

View File

@ -19,8 +19,8 @@ import (
func main() { func main() {
const ( const (
feetInMeters = 0.3048 feetInMeters float64 = 0.3048
feetInYards = feetInMeters / 0.9144 feetInYards = feetInMeters / 0.9144
) )
arg := os.Args[1] arg := os.Args[1]

View File

@ -102,8 +102,8 @@ fmt.Println(a || b)
```go ```go
// Let's say that there are two functions like this: // Let's say that there are two functions like this:
// //
// super() which returns true and prints "super ". // isOn() which returns true and prints "on ".
// duper() which returns false and prints "duper ". // isOff() which returns false and prints "off ".
// //
// Remember: Logical operators short-circuit. // Remember: Logical operators short-circuit.
@ -111,37 +111,37 @@ package main
import "fmt" import "fmt"
func main() { func main() {
_ = duper() && super() _ = isOff() && isOn()
_ = super() || duper() _ = isOn() || isOff()
} }
// Don't mind about these functions. // Don't mind about these functions.
// Just focus on the problem. // Just focus on the problem.
// They are here just for you to understand what's going on better. // They are here just for you to understand what's going on better.
func super() bool { func isOn() bool {
fmt.Print("super ") fmt.Print("on ")
return true return true
} }
func duper() bool { func isOff() bool {
fmt.Print("duper ") fmt.Print("off ")
return false return false
} }
``` ```
1. "super duper super duper " 1. "on off on off "
2. "duper super " *CORRECT* 2. "off on " *CORRECT*
3. "duper super super duper " 3. "off on on off "
4. "super duper " 4. "on off "
> **1, 3:** Remember: Logical operators short-circuit. > **1, 3:** Remember: Logical operators short-circuit.
> **2:** That's right. > **2:** That's right.
> >
> In: `duper() && super()`, `duper()` returns false, so, logical AND operator short-circuits and doesn't call `super()`; so it prints: `"duper "`. > In: `isOff() && isOn()`, `isOff()` returns false, so, logical AND operator short-circuits and doesn't call `isOn()`; so it prints: `"off "`.
> >
> Then, in: `super() || duper()`, `super()` returns true, so, logical OR operator short circuits and doesn't call `duper()`; so it prints `"super "`. > Then, in: `isOn() || isOff()`, `isOn()` returns true, so, logical OR operator short circuits and doesn't call `isOff()`; so it prints `"on "`.
> **4:** Think again. > **4:** Think again.
Example program is [here](https://play.golang.org/p/C-syhwgXSx2). Example program is [here](https://play.golang.org/p/6z3afaOf7yT).

View File

@ -15,10 +15,10 @@ if (mood == "perfect") {
} }
``` ```
1. `if {mood == perfect}` 1. `if {mood == "perfect"}`
2. `if [mood == perfect]` 2. `if [mood == "perfect"]`
3. `if mood = perfect` 3. `if mood = "perfect"`
4. `if mood == perfect` *CORRECT* 4. `if mood == "perfect"` *CORRECT*
> **1, 2:** That's a syntax error. Try again. > **1, 2:** That's a syntax error. Try again.
> >