Unit #5-01
Learning Outcome
At the end of this lesson, you will be able to:
go over selection component
understand and use an if statement
Review
debugging and break points in Chrome inspector
Lesson
go over selection component
NOTE:
you need to add in the CC and JS file from the repo into your project
you also need to reference it inside your idex.html
all our programs so far have been linear
go over linear flow-charts
go over "Boolean Expression" and "If ... Then"
go over if-then flowchart
diamond is boolean expression
you MUST have a "yes" and "no"
go over "Random Numbers"
Math.random()
const randomNumber = Math.floor(Math.random() * 6) + 1 // returns a random integer from 1 to 6 into variable "randomNumber"
problem with "pseudo-random numbers" and seeds
Daily Assignment
create a program that:
ensure your program has a complete GUI and follow all the steps to solve the problem
randomly picks a number from 1 to 6
do not show it to the user, just keep it in memory in a variable
asks the user to pick a number from 1 to 6
use an if ... then statement to tell them if they got it correctly
use a 2nd if ... then to tell them is they got it wrong!
you should place the "random number generation" outside of the function call, so it is run once (1) when the webpage first loads and then does not change; so it is easier to guess!
Extra
do the above program in the terminal
import (
"fmt" "math/rand" "time")
func main() {
s1 := rand.NewSource(time.Now().UnixNano()) r1 := rand.New(s1) fmt.Println(r1.Intn(100))
fmt.Println("\nDone.")}
Selection Component
NOTE: The generation of the random number is outside the function; this is so it is generated just once and does not change. YES, it is a global variable.