Everything You Need to Code, You Learned in Kindergarten
Special thanks to our slide sponsor:
Join the conversation with #ONA17
Your Spirit Guides
Lindsey�COOK
Digital Skills Editor�The New York Times
@Lindzcook
Ashlyn�STILL
Graphics Editor�Reuters
@Ashlynstill
What is Programming?
Programming Concepts
Warm-Up
Warm-Up
What worked? What didn’t?
Object 1:
Shape: Circle
Width: 2 inches
Shaded? Yes
Coordinates: (3, 3)
Object 2:
Shape: Square
Width: 4 inches
Shaded? No
Coordinates: (1, 2), (1, -2), (4,2), (4,-2)
Object 3:
Shape: Triangle
Width: 4 inches
Shaded? Yes
Coordinates: (-4,-1), (-3,5), (1.2, 0)
Programming Concepts
Object 1:
Shape = “Circle”
WidthInInches = 2
Shaded = TRUE
Coordinates = [3, 3]
Object 2:
Shape = “Square”
WidthInInches = 4
Shaded = FALSE
Coordinates: = [[1, 2], [1, -2], [4,2], [4,-2]]
Object 3:
Shape = “Triangle”
WidthInInches = 4
Shaded = TRUE
Coordinates = [[-4,-1], [-3,5], [1.2, 0]]
Programming Concepts
Object 1:
Shape = “Circle” String
WidthInInches = 2 Number
Shaded = TRUE Boolean
Coordinates = [3, 3] Array
Object 2:
Shape = “Square” String
WidthInInches = 4 Number
Shaded = FALSE Boolean
Coordinates: = [[1, 2], [1, -2], [4,2], [4,-2]]
Object 3:
Shape = “Triangle” String
WidthInInches = 4 Number
Shaded = TRUE Boolean
Coordinates = [[-4,-1], [-3,5], [1.2, 0]] Array
More Practice With Variables
Programming Concepts
You are an ONA Object.
More Practice With Variables
ONA Objects Have Four Variables:
More Practice With Variables
ONA Object
More Practice With Variables
ONA Object
Together, we are an Array of these ONA Objects.
More Practice With Variables
ThisRoom = [ person1, person2, person3, person 4, person5, person6, person7]
More Practice With Variables
ThisRoom = [ person1, person2, person3,
person 4, person5, person6, person7]
Programs start counting at 0.
0
1
2
3
4
5
6
ONAObject[0].Name
Who’s number 1?
More Practice With Variables
ONAObject[2].Name
ONAObject[15].Name
More Practice With Variables
ONAObject[8].Name
ONAObject[3].Name
More Practice With Variables
ONAObject[28].Name
ONAObject[42].Name
More Practice With Variables
ONAObject[48].YearsatJob
ONAObject[35].YearsatJob
More Practice With Variables
ONAObject[12].YearsatJob
ONAObject[7].YearsatJob
More Practice With Variables
ONAObject[22].FirstTimeatONA
ONAObject[39].FirstTimeatONA
More Practice With Variables
ONAObject[44].FirstTimeatONA
ONAObject[49].FirstTimeatONA
More Practice With Variables
Arrays coming, put your thinking cap on!
More Practice With Variables
ONAObject[4].NamesofColleaguesHere
ONAObject[19].NamesofColleaguesHere
More Practice With Variables
ONAObject[34].NamesofColleaguesHere[1]
ONAObject[21].NamesofColleaguesHere[1]
More Practice With Variables
ONAObject[26].NamesofColleaguesHere[0]
ONAObject[1].NamesofColleaguesHere[0]
More Practice With Variables
Red Light, Green Light
Programming Concepts
Conditional
Performs a different action based on if a boolean value evaluates to true or false
If someCondition is True:
Do something
If someCondition is False:
Do something else (or do nothing)
Conditionals: Red Light, Green Light
For all items in ONAObject:
Paces = 0
#create a new variable named Paces and set it to #zero. This is a comment! Meaning you can see it but #the computer knows it isn’t code
Conditionals: Red Light, Green Light
For all items in ONAObject:
If(FirstTimeatONA)
Paces = Paces + 2
Translation: Set Paces equal to whatever Paces is now, plus 2.
Conditionals: Red Light, Green Light
For all items in ONAObject:
If(Name is “Eric”)
Paces = Paces - 1
Conditionals: Red Light, Green Light
For all items in ONAObject:
If(Name is “Ashlyn”)
Paces = Paces - 1
Else
Paces = Paces + 3
Conditionals: Red Light, Green Light
For all items in ONAObject:
If(YearsAtJob > 3)
Paces = Paces + 3
Conditionals: Red Light, Green Light
For all items in ONAObject:
If(YearsAtJob is 1)
Paces = Paces * 1
Conditionals: Red Light, Green Light
For all items in ONAObject:
If(NamesofColleaguesHere.length > 3)
Paces = Paces - Name.length
Else
Paces = Paces + Name.length
Conditionals: Red Light, Green Light
For all items in ONAObject:
If(Name.length > 5)
Paces = Paces + 5
Conditionals: Red Light, Green Light
For all items in ONAObject:
If(Name.length > 5)
Paces = Paces + 5
Else if (Name.length is 6)
Paces = Paces + 6
Conditionals: Red Light, Green Light
For all items in ONAObject:
If(Name.length > 7)
Paces = Paces + 7
Else if (Name.length is 8)
Paces = Paces + 8
Else if (Name.length < 5)
Paces = Paces + 4
Conditionals: Red Light, Green Light
For all items in ONAObject:
If(Name.length > 7)
Paces = Paces + 7
Else if (Name.length is 8)
Paces = Paces + 8
Else if (Name.length < 5)
Paces = Paces + 4
Else
Paces = Paces - 4
Programming Concepts
Conditionals: Red Light, Green Light
For all items in ONAObject:
If(YearsAtJob is 1)
Paces = Paces * 1
Programming Concepts
Loops: Red Light, Green Light
For all items in ONAObject:
If(YearsAtJob is 1)
Paces = Paces + 1
If (ONAObject[0].YearsAtJob is 1)
ONAObject[0].Paces = ONAObject[0].Paces + 1
If (ONAObject[1].YearsAtJob is 1)
ONAObject[1].Paces = ONAObject[1].Paces + 1
If (ONAObject[2].YearsAtJob is 1)
ONAObject[2].Paces = ONAObject[2].Paces + 1
Programming Concepts
Let’s Write a News Story
Let’s Write a News Story
Let’s Write a News Story
Let’s Write a News Story
Programming Concepts
Let’s Write a News Story
WriteNewsStory(variables here!){
#Code here
}
What Variables Do You Need?
Let’s Write a News Story
WriteNewsStory(variables here!){
#Code here
}
Let’s Write a News Story
First Paragraph: Macy’s Inc. (M) on Wednesday reported fiscal third-quarter net income of $118 million.
Let’s Write a News Story
First Paragraph: Macy’s Inc. (M) on Wednesday reported fiscal third-quarter net income of $118 million.
Let’s Write a News Story
First Paragraph: Macy’s Inc. (M) on Wednesday reported fiscal third-quarter net income of $118 million.
Variables needed: Company (string), abbreviation (string), day (string), quarter (number/string), netIncome (Number)
Let’s Write a News Story
WriteNewsStory(variables here!){
#Code here
}
Let’s Write a News Story
WriteNewsStory(Company, abbreviation, day, quarter, netIncome){
NewsStory = Company + “ “ + abbreviation + “ on ” + day + “ reported fiscal ” + quarter + “- quarter net income of $” + netIncome + “ million .”
}
Macy’s Inc. (M) on Wednesday reported fiscal third-quarter net income of $118 million.
Let’s Write a News Story
WriteNewsStory(Company, abbreviation, day, quarter, netIncome){
NewsStory = Company + “ “ + abbreviation + “ on ” + day + “ reported fiscal ” + quarter + “- quarter net income of $” + netIncome + “ million .”
}
Apple Inc. (AAPL) on Thursday reported fiscal second-quarter net income of $871 million.
Let’s Write a News Story
WriteNewsStory(Company, abbreviation, day, quarter, netIncome){
NewsStory = Company + “ “ + abbreviation + “ on ” + day + “ reported fiscal ” + quarter + “- quarter net income of $” + netIncome + “ million .”
}
Home Depot Inc. (HD) on Friday reported fiscal fourth-quarter net income of $30 million.
Programming Concepts
Let’s Write a News Story
function WriteNewsStory(Company, abbreviation, day, quarter, netIncome){
//function in Javascript
var NewsStory = Company + “ “ + abbreviation + “ on ” + day + “ reported fiscal ” + quarter + “- quarter net income of $” + netIncome + “ million .”;
}
Let’s Write a News Story
def WriteNewsStory(Company, abbreviation, day, quarter, netIncome):
# function in Python
NewsStory = Company + “ “ + abbreviation + “ on ” + day + “ reported fiscal ” + quarter + “- quarter net income of $” + netIncome + “ million .”
Programming Concepts
Let’s Write a News Story
Let’s Write a News Story
WriteNewsStory(variables here!){
#Code here
}
Fizz Buzz Test
Fizz Buzz Test
Fizz Buzz Test: Hints
For number 1-100 (loop)
//write conditionals here!
Fizz Buzz Test
For number 1-100 (loop)
If number divisible by 3 AND divisible by 5
Print FizzBuzz
Else if number divisible by 3
Print Buzz
Else if number divisible by 5
Print Fizz
Else
Print number
for myNumber in xrange(1,101):
if myNumber % 5 == 0 and myNumber % 3 == 0:
print “FizzBuzz”
elif myNumber % 3 == 0:
print “Buzz”
elif myNumber % 5 == 0:
print “Fizz”
else:
print myNumber
Where Do I Go From Here?
Where Do I Go From Here?
We Support