Open rodriggj opened 2 years ago
color
variable to "dark green"color
directly Instead, use the color
variable again while assigning to color
RESTRICTIONS
WRONG ANSWER, DO NOT DO THIS:
color = "dark green"
HINT
Repeated steps above, with this logic
package main
import (
"fmt"
)
func main() {
color := "green"
nc := "dark"
fmt.Println("New Color:", nc+" "+color)
}
n
variablen
variableHINT Example: 3 * 2 = 6
Repeated same process with the following logic
package main
import (
"fmt"
)
func main() {
n := 3.14 * 2
fmt.Println("3.14 * 2 = ", n)
}
// EXERCISE: Find the Rectangle's Perimeter
//
// 1. Find the perimeter of a rectangle
// Its width is 5
// Its height is 6
//
// 2. Assign the result to the perimeter
variable
//
// 3. Print the perimeter
variable
//
// HINT
// Formula = 2 times the width and height
//
// EXPECTED OUTPUT
// 22
//
// BONUS
// Find more formulas here and calculate them in new programs
// https://www.mathsisfun.com/area.html
// ---------------------------------------------------------
func main() { // UNCOMMENT THE CODE BELOW:
// var (
// perimeter int
// width, height = 5, 6
// )
// USE THE VARIABLES ABOVE WHEN CALCULATING YOUR RESULT
// ADD YOUR CODE BELOW
}
Repeated the same process with the following logic
package main
import "fmt"
func main() {
var (
perimeter int
width, height = 5, 6
)
perimeter = 2 * (width + height)
fmt.Println("Perimeter equals: ", perimeter)
}
// ---------------------------------------------------------
// EXERCISE: Multi Assign
//
// 1. Assign "go" to lang
variable
// and assign 2 to version
variable
// using a multiple assignment statement
//
// 2. Print the variables
//
// EXPECTED OUTPUT
// go version 2
// ---------------------------------------------------------
func main() { // DO NOT TOUCH THIS var ( lang string version int )
// ADD YOUR CODE BELOW
// DO NOT TOUCH THIS
fmt.Println(lang, "version", version)
}
Repeated same process with the following logic
package main
import "fmt"
func main() {
// DO NOT TOUCH THIS
var (
lang string
version int
)
// ADD YOUR CODE BELOW
lang = "go"
version = 2
// DO NOT TOUCH THIS
fmt.Println(lang, "version", version)
}
// --------------------------------------------------------- // EXERCISE: Multi Assign #2 // // 1. Assign the correct values to the variables // to match to the EXPECTED OUTPUT below // // 2. Print the variables // // HINT // Use multiple Println calls to print each sentence. // // EXPECTED OUTPUT // Air is good on Mars // It's true // It is 19.5 degrees // ---------------------------------------------------------
Repeated same process with the following logic
package main
import (
"fmt"
)
func main() {
var (
planet string
isTrue bool
temp float64
)
planet, isTrue, temp = "mars", true, 19.5
fmt.Println("Air is good on", planet)
fmt.Println("It's", isTrue)
fmt.Println("It is", temp, "degrees")
}
NOTE: You don't need to add spacing (e.g "Air is good on ", planet -> "Air is good on", planet).
Exercise 1: make it blue
color
variable's value to "blue"Process:
import "fmt"
func main() { var color string = "green" color = "blue"
}