refactor: exercises for the first 4 sections
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
1. Print your name and your best friend's name using Println twice. [Check out this challenge here](https://github.com/inancgumus/learngo/tree/master/02-write-your-first-program/exercises/01).
|
1. **Print your name and your best friend's name** using Println twice. [Check out this exercise here](https://github.com/inancgumus/learngo/tree/master/02-write-your-first-program/exercises/01).
|
||||||
|
|
||||||
2. Print your GOPATH using `go env` tool. [Check out this challenge here](https://github.com/inancgumus/learngo/tree/master/02-write-your-first-program/exercises/02).
|
2. **Print your GOPATH** using `go env` tool. [Check out this exercise here](https://github.com/inancgumus/learngo/tree/master/02-write-your-first-program/exercises/02).
|
||||||
|
|
||||||
3. **Say hello to yourself.**
|
3. **Say hello to yourself.**
|
||||||
|
|
@ -8,7 +8,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Use your own package
|
||||||
|
//
|
||||||
// Create a few Go files and call their functions from
|
// Create a few Go files and call their functions from
|
||||||
// the main function.
|
// the main function.
|
||||||
//
|
//
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Try the scopes
|
||||||
|
//
|
||||||
// 1. Create two files: main.go and printer.go
|
// 1. Create two files: main.go and printer.go
|
||||||
//
|
//
|
||||||
// 2. In printer.go:
|
// 2. In printer.go:
|
||||||
@ -24,9 +25,6 @@ package main
|
|||||||
// 4. In printer.go:
|
// 4. In printer.go:
|
||||||
// 1. Call the bye function from
|
// 1. Call the bye function from
|
||||||
// inside the hello function
|
// inside the hello function
|
||||||
//
|
|
||||||
// 5. In main.go:
|
|
||||||
// 1.
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Rename imports
|
||||||
|
//
|
||||||
// 1- Import fmt package three times with different names
|
// 1- Import fmt package three times with different names
|
||||||
//
|
//
|
||||||
// 2- Print a few messages using those imports
|
// 2- Print a few messages using those imports
|
||||||
|
@ -8,11 +8,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Shy Semicolons
|
||||||
// 1. Greet a few people
|
//
|
||||||
// 2. Try to type your statements separating them using
|
// 1. Try to type your statements by separating them using
|
||||||
// semicolons
|
// semicolons
|
||||||
// 3. Observe how Go fixes them for you
|
//
|
||||||
|
// 2. Observe how Go fixes them for you
|
||||||
|
//
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
func main() {
|
func main() {
|
@ -0,0 +1,23 @@
|
|||||||
|
// For more tutorials: https://blog.learngoprogramming.com
|
||||||
|
//
|
||||||
|
// Copyright © 2018 Inanc Gumus
|
||||||
|
// Learn Go Programming Course
|
||||||
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||||
|
//
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Uncomment the line of code below; then save the file.
|
||||||
|
//
|
||||||
|
// You will see that Go will fix it automatically.
|
||||||
|
//
|
||||||
|
// This is because, for Go, it doesn't matter whether
|
||||||
|
// you use semicolons between the statements or not.
|
||||||
|
//
|
||||||
|
// It adds them automatically after all.
|
||||||
|
|
||||||
|
/*
|
||||||
|
fmt.Println("inanc"); fmt.Println("lina"); fmt.Println("ebru");
|
||||||
|
*/
|
||||||
|
}
|
@ -1,21 +0,0 @@
|
|||||||
// For more tutorials: https://blog.learngoprogramming.com
|
|
||||||
//
|
|
||||||
// Copyright © 2018 Inanc Gumus
|
|
||||||
// Learn Go Programming Course
|
|
||||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
||||||
//
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// uncomment the below line of code; then save the file
|
|
||||||
//
|
|
||||||
// you will see that Go will fix it automatically
|
|
||||||
//
|
|
||||||
// this is because, for Go, it doesn't matter whether
|
|
||||||
// you use semicolons between statements or not.
|
|
||||||
//
|
|
||||||
// it adds them automatically after all.
|
|
||||||
|
|
||||||
// fmt.Println("inanc"); fmt.Println("lina"); fmt.Println("ebru");
|
|
||||||
}
|
|
@ -8,10 +8,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Naked Expression
|
||||||
// Try to type just "Hello" on a line.
|
//
|
||||||
// Do not use Println
|
// 1. Try to type just "Hello" on a line.
|
||||||
// Observe the error
|
// 2. Do not use Println
|
||||||
|
// 3. Observe the error
|
||||||
|
//
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
func main() {
|
func main() {
|
@ -0,0 +1,25 @@
|
|||||||
|
// For more tutorials: https://blog.learngoprogramming.com
|
||||||
|
//
|
||||||
|
// Copyright © 2018 Inanc Gumus
|
||||||
|
// Learn Go Programming Course
|
||||||
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||||
|
//
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Uncomment the code line below to see the error.
|
||||||
|
|
||||||
|
/*
|
||||||
|
"Hello"
|
||||||
|
*/
|
||||||
|
|
||||||
|
// It will say: "evaluted but not used"
|
||||||
|
//
|
||||||
|
// Because:
|
||||||
|
// "Hello" literal returns a value but there isn't any
|
||||||
|
// statement which uses it.
|
||||||
|
//
|
||||||
|
// So:
|
||||||
|
// You can't use expressions alone without statements.
|
||||||
|
}
|
@ -1,20 +0,0 @@
|
|||||||
// For more tutorials: https://blog.learngoprogramming.com
|
|
||||||
//
|
|
||||||
// Copyright © 2018 Inanc Gumus
|
|
||||||
// Learn Go Programming Course
|
|
||||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
||||||
//
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// uncomment to see the error
|
|
||||||
|
|
||||||
// "Hello"
|
|
||||||
|
|
||||||
// It says "evaluted but not used" because
|
|
||||||
// the "Hello" expression returned a value
|
|
||||||
// and no statement has used it
|
|
||||||
|
|
||||||
// You can't use expressions without statements
|
|
||||||
}
|
|
@ -8,14 +8,19 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Operators combine the expressions
|
||||||
// Print the expected output using operators
|
//
|
||||||
|
// Print the expected output below using the string
|
||||||
|
// concatenation operator.
|
||||||
|
//
|
||||||
|
// HINT
|
||||||
|
// Use + operator multiple times to create "Hello!!!?".
|
||||||
//
|
//
|
||||||
// EXPECTED OUTPUT
|
// EXPECTED OUTPUT
|
||||||
// "Hello!!!?"
|
// "Hello!!!?"
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// use + operator below multiple times
|
|
||||||
// fmt.Println("Hello!" + ?)
|
// fmt.Println("Hello!" + ?)
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Operators bind multiple expressions together
|
// Operators combine multiple expressions together
|
||||||
// as if there's a single expression
|
// as if there's a single expression.
|
||||||
fmt.Println("Hello!" + "!" + "!" + "?")
|
fmt.Println("Hello!" + "!" + "!" + "?")
|
||||||
}
|
}
|
@ -8,10 +8,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Print the Go Version
|
||||||
// 1- Look at runtime package documentation
|
//
|
||||||
// 2- Find the func that returns the Go version
|
// 1. Look at the runtime package documentation
|
||||||
// 3- Print the Go version by calling that func
|
// 2. Find the func that returns the Go version
|
||||||
|
// 3. Print the Go version by calling that func
|
||||||
//
|
//
|
||||||
// HINT
|
// HINT
|
||||||
// It's here: https://golang.org/pkg/runtime
|
// It's here: https://golang.org/pkg/runtime
|
@ -10,11 +10,12 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// EXERCISE
|
// EXERCISE: Comment out
|
||||||
// Use single and multiline comments to comment Printlns
|
//
|
||||||
|
// Use single and multiline comments to comment Printlns.
|
||||||
//
|
//
|
||||||
// EXPECTED OUTPUT
|
// EXPECTED OUTPUT
|
||||||
// None
|
// You shouldn't see any output after you're done.
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
func main() {
|
func main() {
|
Reference in New Issue
Block a user