refactor: exercises for the first 4 sections

This commit is contained in:
Inanc Gumus
2018-10-22 21:05:42 +03:00
parent 1cbcfca10a
commit f860bc6895
18 changed files with 87 additions and 69 deletions

View File

@ -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.**

View File

@ -8,7 +8,8 @@
package main
// ---------------------------------------------------------
// EXERCISE
// EXERCISE: Use your own package
//
// Create a few Go files and call their functions from
// the main function.
//

View File

@ -8,7 +8,8 @@
package main
// ---------------------------------------------------------
// EXERCISE
// EXERCISE: Try the scopes
//
// 1. Create two files: main.go and printer.go
//
// 2. In printer.go:
@ -24,9 +25,6 @@ package main
// 4. In printer.go:
// 1. Call the bye function from
// inside the hello function
//
// 5. In main.go:
// 1.
// ---------------------------------------------------------
func main() {

View File

@ -8,7 +8,8 @@
package main
// ---------------------------------------------------------
// EXERCISE
// EXERCISE: Rename imports
//
// 1- Import fmt package three times with different names
//
// 2- Print a few messages using those imports

View File

@ -8,11 +8,13 @@
package main
// ---------------------------------------------------------
// EXERCISE
// 1. Greet a few people
// 2. Try to type your statements separating them using
// EXERCISE: Shy Semicolons
//
// 1. Try to type your statements by separating them using
// semicolons
// 3. Observe how Go fixes them for you
//
// 2. Observe how Go fixes them for you
//
// ---------------------------------------------------------
func main() {

View File

@ -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");
*/
}

View File

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

View File

@ -8,10 +8,12 @@
package main
// ---------------------------------------------------------
// EXERCISE
// Try to type just "Hello" on a line.
// Do not use Println
// Observe the error
// EXERCISE: Naked Expression
//
// 1. Try to type just "Hello" on a line.
// 2. Do not use Println
// 3. Observe the error
//
// ---------------------------------------------------------
func main() {

View File

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

View File

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

View File

@ -8,14 +8,19 @@
package main
// ---------------------------------------------------------
// EXERCISE
// Print the expected output using operators
// EXERCISE: Operators combine the expressions
//
// Print the expected output below using the string
// concatenation operator.
//
// HINT
// Use + operator multiple times to create "Hello!!!?".
//
// EXPECTED OUTPUT
// "Hello!!!?"
// ---------------------------------------------------------
func main() {
// use + operator below multiple times
// fmt.Println("Hello!" + ?)
}

View File

@ -10,7 +10,7 @@ package main
import "fmt"
func main() {
// Operators bind multiple expressions together
// as if there's a single expression
// Operators combine multiple expressions together
// as if there's a single expression.
fmt.Println("Hello!" + "!" + "!" + "?")
}

View File

@ -8,10 +8,11 @@
package main
// ---------------------------------------------------------
// EXERCISE
// 1- Look at runtime package documentation
// 2- Find the func that returns the Go version
// 3- Print the Go version by calling that func
// EXERCISE: Print the Go Version
//
// 1. Look at the runtime package documentation
// 2. Find the func that returns the Go version
// 3. Print the Go version by calling that func
//
// HINT
// It's here: https://golang.org/pkg/runtime

View File

@ -10,11 +10,12 @@ package main
import "fmt"
// ---------------------------------------------------------
// EXERCISE
// Use single and multiline comments to comment Printlns
// EXERCISE: Comment out
//
// Use single and multiline comments to comment Printlns.
//
// EXPECTED OUTPUT
// None
// You shouldn't see any output after you're done.
// ---------------------------------------------------------
func main() {