SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
Build a Virtual Pet with Javascript
January 2018
Wi-Fi Name: Deskhub-main
PW: stake2017!
http://bit.ly/virtual-pet-sd
1
Welcome to "Build a Virtual Pet with Javascript". The Wi-Fi network is X and the password is Y The website for this class is Z.
Speaker notes
Instructor
Jasmine Kim
Bootcamp Graduate
Soon to be System Engineer
Former Accountant
TA's
2
Let me start with a little about me. My name is X and my background is Y
I am working with Thinkful to teach this class because Z
Speaker notes
About you
What's your name?
What's your goal?
What is your coding background?
3
I'd love to learn a little more about you guys. So can we go around the room and can everyone give us your name, what your goal is for attending
the class and your programming background?
Speaker notes
About Thinkful
Thinkful helps people become developers or data scientists
through one-on-one mentorship and project-based learning
These workshops are built using this approach.
4
Thinkful is hosting the event tonight. Thinkful is a coding bootcamp built on a belief in one-on-one mentorship and project based learning.
We believe making a career transition is hard and to be successful, you'll need a lot of personal support and learning that's grounded in real-world
experience. Our workshop today is designed with this view in mind.
Speaker notes
Suggestions for learning
Don't treat this as a drill, we're making something real
Don't get discouraged, struggle leads to mastery
Don't be shy, take full advantage of our support
5
To get the most out of this class, we have three suggestions for getting the most our of this experience.
The first suggestion is to realize we're building something real and accept that's going to be messy. There will be many right answers and a good
project is never done. There will always be ways you can make it better.
Whatever your level, we're going to push you so it's a little hard. Even basic addition was hard at one point. Struggle is a part of mastery. Try not to
get discouraged.
Finally, we're here to help. Take advantage of that support, make sure to ask questions during lecture when you're confused. Make sure you call
your TA when you need help. When coding, be resourceful. Always!
Speaker notes
This is what we're making
6
Today we're building a simple virtual pet. We can click three different buttons to feed our pet, play with our bet, and have our pet do some exercise.
When we click on these buttons, we'll increase or decrease the weight or happiness of our pet.
Speaker notes
Agenda
Starter code review (5 min)
Learn key Javascript concepts (25 min)
Build your app! (40 min)
Go over solutions (10 min)
Next steps (10 min)
7
I’ll start by walking you through the HTML/CSS starter code so you have a reference of what you’ll be working with. Then I’ll go over important
Javascript concepts that you’ll need to complete the app. You’ll then build the app during which time the TA’s and myself will be walking around to
help you guys out. At the end we’ll go over solutions and then cover next steps for continuing your learning.
Speaker notes
Starter code
http://bit.ly/virtual-pet-starter-code
8
Go ahead and go to this url to get the starter code. We’re using a online code editor called Glitch which will let us see the result of our code really
quickly.
On the README.MD file you should see an overview of the project and the challenges you'll need to complete. The files we’ll be using today on the
left are client.js and index.html. You can ignore style.css, server.js, package.json and .env. At the bottom of the Readme file we've added some
helpful links for further help on particular concepts.
Lets look at the index.html file to see how our app is structured. We have an image which includes a picture of our pet. We're displaying the pet's
name, weight, and level of happiness. Below that are three buttons. One to give the pet a treat, increasing it's weight and happiness. One is to play
with our pet, decreasing it's weight and increasing it's happiness. The third is exercise which decreases it's weight and happiness.
All of the code you’ll be writing will be in client.js but you may need to refer to the html and css file to solve some of the problems. Once you’ve
written some code, click the “Show Live” button at the top to open a new tab that will automatically update as you edit your code.
Speaker notes
Defining a variable with Javascript
var firstVariable = 20
Initialize variable
Name of variable
Value of variable
9
Let's start with reviewing variables in Javascript. Variables let us assign some value to a a string. We use variables to store information that we'll use
when our app is running.
To define a variable in Javascript, we start with the keyword "var". We then give our variable a name. The name should start with a letter. Try to
make sure your variable names are descriptive. It's ok if they are long.
Then we set that variable name equal to some value. That value can be any data structure in JS including numbers and strings.
Speaker notes
More about variables
10
Alright lets try writing this out. Add var firstVariable = 20. If we type firstVariable now, what is going to happen?
The number 20 is stored in the variable so every time we use that variable, we're referring to the 20.
With a number, we can also increment or decrement that number. Once we define the variable, we can re-define it as either more or less. So we
could do firstVariable = firstVariable + 1 to change our variable from 20 to 21. In this way, an equal sign in JS is different than in math. A single equal
sign means we're assigning a value, not saying two things are equal.
What other things can we store in a variable? In Javascript we can store pretty much everything in a variable. We can store booleans and strings as
well. Lets see examples of each of those.
Instead of a number, set firstVariable equal to a string. In JS, when we put a value in quotes, it assumes its a string. Let's console.log the string. We
can do the same with booleans.
Speaker notes
Introducing our pet "object"
Name
"Thinkpup"
Weight
6
Happiness
0
11
Lets say we want to store a bunch of different information in one variable, we can do that with a Javascript object. We'll be using a JS object
remember all the aspects of our virtual pet.
An object will basically have a list of "keys" and "values". So we can store all the information about our pet in one place. In this case, we'll have three
items in our "list". The name of our pet, which would be a string. The weight which would be a number. And how happy they are, which will also be a
number.
We can "get" and "set" our values by grabbing them from the object with the "key" which is always a string. In this case, our key for "Thinkpup" is
"name".
Speaker notes
Working with objects
12
Creating an object
Define an object with curly brackets. The "key" is always a string. The value can be whatever value we like. A Javascript object can hold all sorts of
values in one variable.
Retrieving a value
We can retrieve a value by saying pet_info.name or pet_info['name']
Changing a value
We can change a value by saying pet_inf['name'] = "Nala"
Speaker notes
Basic functions
13
A function lets you separate your code into bite-sized pieces which you can use over again.
When you write a function to use later, you are “declaring” it. When you use (or run) that function you are “calling” it.
To call a function, we simply write doSomething() and then the function is run.
Speaker notes
If, then, else
pet is hungry feed it
go to park
if true
if false
14
In all programming languages there exist a way to tell the computer that if X happens, do this, if y happens, do that. In Javascript we use if, then,
else statement. So we tell the computer, if this condition is true, say the pet is hungry, feed it. If it's not hungry (or that condition is false), go to the
park. After this, continue running the program.
Speaker notes
Conditionals example
15
This is how we'd write that concept in Javascript. We have an "if" keyword and then some condition that could either be True or False in
parentheses. If it's true, it would run the code in the first bracket. If it's not true, we'd run the code in the else block.
Speaker notes
Real developers use Google... a lot
16
With that you should be ready to start the challenges. One last note before we do the first challenge together.
Google is an everyday part of being a developer. A key part of becoming a developer is getting comfortable using Google to learn and look up things.
The more you code, the more you will use Google, not the other way around.
Speaker notes
Let's work on the first step together
http://bit.ly/tf-virtual-pet
17
Alright, with that let's start building our app.
On the left, you can see the files you'll be working on. The Readme will give you instructions. You'll be writing your code in client.js. You shouldn't
need to touch any of the other files.
After you write your code, it will automatically be saved. At any point you can hit "Show Live" to see a live version of your app.
Let's start the first step together. So in this first step, we want to create our pet_info object with three keys. How would we do that? Feel free to
name your pet whatever you like and set it's starting happiness and weight to whatever you like.
(Assign TA's to different sections of class)
Speaker notes
Solution
18
Alright. Let's go over the solutions to the main challenges.
For each of the functions, we're going to do a version of the same thing. We're going to first grab the value from our object and then assign it to that
value plus or minus some number.
For our third step, we want to make sure weight can't go below zero. To do this, we add a function that checks weight before we update it in the
HTML. If weight is below one, it should equal one.
Speaker notes
Ways to keep learning
19
Thinkful's Free Resource
HTML, CSS and JavaScript
Unlimited mentor-led Q&A sessions
Personal Program Manager
OnlyOnly availableavailable during this eventduring this event
bit.ly/webdev-sd
20

Mais conteúdo relacionado

Semelhante a Vpet sd-1.25.18

Build a virtual pet with javascript (april 2017)
Build a virtual pet with javascript (april 2017)Build a virtual pet with javascript (april 2017)
Build a virtual pet with javascript (april 2017)
Thinkful
 
Build a virtual pet with javascript (may 2017)
Build a virtual pet with javascript (may 2017)Build a virtual pet with javascript (may 2017)
Build a virtual pet with javascript (may 2017)
Thinkful
 
Learn python
Learn pythonLearn python
Learn python
mocninja
 
Android tutorials7 calculator
Android tutorials7 calculatorAndroid tutorials7 calculator
Android tutorials7 calculator
Vlad Kolesnyk
 
D:\Documents And Settings\Jamel King\Desktop\Washrinserepeat1
D:\Documents And Settings\Jamel King\Desktop\Washrinserepeat1D:\Documents And Settings\Jamel King\Desktop\Washrinserepeat1
D:\Documents And Settings\Jamel King\Desktop\Washrinserepeat1
guestc11121
 

Semelhante a Vpet sd-1.25.18 (20)

Javascript breakdown-workbook
Javascript breakdown-workbookJavascript breakdown-workbook
Javascript breakdown-workbook
 
Web app-la-jan-2
Web app-la-jan-2Web app-la-jan-2
Web app-la-jan-2
 
Bavpwjs110
Bavpwjs110Bavpwjs110
Bavpwjs110
 
Build a Virtual Pet with JavaScript (May 2017, Santa Monica)
Build a Virtual Pet with JavaScript (May 2017, Santa Monica) Build a Virtual Pet with JavaScript (May 2017, Santa Monica)
Build a Virtual Pet with JavaScript (May 2017, Santa Monica)
 
Python breakdown-workbook
Python breakdown-workbookPython breakdown-workbook
Python breakdown-workbook
 
Bavpwjs221
Bavpwjs221Bavpwjs221
Bavpwjs221
 
Build a virtual pet with javascript (april 2017)
Build a virtual pet with javascript (april 2017)Build a virtual pet with javascript (april 2017)
Build a virtual pet with javascript (april 2017)
 
Most asked JAVA Interview Questions & Answers.
Most asked JAVA Interview Questions & Answers.Most asked JAVA Interview Questions & Answers.
Most asked JAVA Interview Questions & Answers.
 
Build a virtual pet with javascript (may 2017)
Build a virtual pet with javascript (may 2017)Build a virtual pet with javascript (may 2017)
Build a virtual pet with javascript (may 2017)
 
Learn python
Learn pythonLearn python
Learn python
 
Android tutorials7 calculator
Android tutorials7 calculatorAndroid tutorials7 calculator
Android tutorials7 calculator
 
Mobile App Feature Configuration and A/B Experiments
Mobile App Feature Configuration and A/B ExperimentsMobile App Feature Configuration and A/B Experiments
Mobile App Feature Configuration and A/B Experiments
 
Grails Worst Practices
Grails Worst PracticesGrails Worst Practices
Grails Worst Practices
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
 
Init() day2
Init() day2Init() day2
Init() day2
 
Init() Lesson 2
Init() Lesson 2Init() Lesson 2
Init() Lesson 2
 
Bavpwjs1113
Bavpwjs1113Bavpwjs1113
Bavpwjs1113
 
Spreadsheets for developers
Spreadsheets for developersSpreadsheets for developers
Spreadsheets for developers
 
D:\Documents And Settings\Jamel King\Desktop\Washrinserepeat1
D:\Documents And Settings\Jamel King\Desktop\Washrinserepeat1D:\Documents And Settings\Jamel King\Desktop\Washrinserepeat1
D:\Documents And Settings\Jamel King\Desktop\Washrinserepeat1
 
Advanced java script essentials v1
Advanced java script essentials v1Advanced java script essentials v1
Advanced java script essentials v1
 

Mais de Thinkful

LA 1/16/18 Intro to Javascript: Fundamentals
LA 1/16/18 Intro to Javascript: FundamentalsLA 1/16/18 Intro to Javascript: Fundamentals
LA 1/16/18 Intro to Javascript: Fundamentals
Thinkful
 
Getting started-jan-9-2018
Getting started-jan-9-2018Getting started-jan-9-2018
Getting started-jan-9-2018
Thinkful
 

Mais de Thinkful (20)

893ff61f-1fb8-4e15-a379-775dfdbcee77-7-14-25-46-115-141-308-324-370
893ff61f-1fb8-4e15-a379-775dfdbcee77-7-14-25-46-115-141-308-324-370893ff61f-1fb8-4e15-a379-775dfdbcee77-7-14-25-46-115-141-308-324-370
893ff61f-1fb8-4e15-a379-775dfdbcee77-7-14-25-46-115-141-308-324-370
 
LA 1/31/18 Intro to JavaScript: Fundamentals
LA 1/31/18 Intro to JavaScript: FundamentalsLA 1/31/18 Intro to JavaScript: Fundamentals
LA 1/31/18 Intro to JavaScript: Fundamentals
 
LA 1/31/18 Intro to JavaScript: Fundamentals
LA 1/31/18 Intro to JavaScript: FundamentalsLA 1/31/18 Intro to JavaScript: Fundamentals
LA 1/31/18 Intro to JavaScript: Fundamentals
 
Itjsf129
Itjsf129Itjsf129
Itjsf129
 
Twit botsd1.30.18
Twit botsd1.30.18Twit botsd1.30.18
Twit botsd1.30.18
 
Build your-own-instagram-filters-with-javascript-202-335 (1)
Build your-own-instagram-filters-with-javascript-202-335 (1)Build your-own-instagram-filters-with-javascript-202-335 (1)
Build your-own-instagram-filters-with-javascript-202-335 (1)
 
Baggwjs124
Baggwjs124Baggwjs124
Baggwjs124
 
Become a Data Scientist: A Thinkful Info Session
Become a Data Scientist: A Thinkful Info SessionBecome a Data Scientist: A Thinkful Info Session
Become a Data Scientist: A Thinkful Info Session
 
LA 1/18/18 Become A Web Developer: A Thinkful Info Session
LA 1/18/18 Become A Web Developer: A Thinkful Info SessionLA 1/18/18 Become A Web Developer: A Thinkful Info Session
LA 1/18/18 Become A Web Developer: A Thinkful Info Session
 
How to Choose a Programming Language
How to Choose a Programming LanguageHow to Choose a Programming Language
How to Choose a Programming Language
 
Batbwjs117
Batbwjs117Batbwjs117
Batbwjs117
 
1/16/18 Intro to JS Workshop
1/16/18 Intro to JS Workshop1/16/18 Intro to JS Workshop
1/16/18 Intro to JS Workshop
 
LA 1/16/18 Intro to Javascript: Fundamentals
LA 1/16/18 Intro to Javascript: FundamentalsLA 1/16/18 Intro to Javascript: Fundamentals
LA 1/16/18 Intro to Javascript: Fundamentals
 
(LA 1/16/18) Intro to JavaScript: Fundamentals
(LA 1/16/18) Intro to JavaScript: Fundamentals(LA 1/16/18) Intro to JavaScript: Fundamentals
(LA 1/16/18) Intro to JavaScript: Fundamentals
 
Websitesd1.15.17.
Websitesd1.15.17.Websitesd1.15.17.
Websitesd1.15.17.
 
Byowwhc110
Byowwhc110Byowwhc110
Byowwhc110
 
Getting started-jan-9-2018
Getting started-jan-9-2018Getting started-jan-9-2018
Getting started-jan-9-2018
 
Introjs1.9.18tf
Introjs1.9.18tfIntrojs1.9.18tf
Introjs1.9.18tf
 
Proglangauage1.10.18
Proglangauage1.10.18Proglangauage1.10.18
Proglangauage1.10.18
 
Batbwjs14
Batbwjs14Batbwjs14
Batbwjs14
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Vpet sd-1.25.18

  • 1. Build a Virtual Pet with Javascript January 2018 Wi-Fi Name: Deskhub-main PW: stake2017! http://bit.ly/virtual-pet-sd 1
  • 2. Welcome to "Build a Virtual Pet with Javascript". The Wi-Fi network is X and the password is Y The website for this class is Z. Speaker notes
  • 3. Instructor Jasmine Kim Bootcamp Graduate Soon to be System Engineer Former Accountant TA's 2
  • 4. Let me start with a little about me. My name is X and my background is Y I am working with Thinkful to teach this class because Z Speaker notes
  • 5. About you What's your name? What's your goal? What is your coding background? 3
  • 6. I'd love to learn a little more about you guys. So can we go around the room and can everyone give us your name, what your goal is for attending the class and your programming background? Speaker notes
  • 7. About Thinkful Thinkful helps people become developers or data scientists through one-on-one mentorship and project-based learning These workshops are built using this approach. 4
  • 8. Thinkful is hosting the event tonight. Thinkful is a coding bootcamp built on a belief in one-on-one mentorship and project based learning. We believe making a career transition is hard and to be successful, you'll need a lot of personal support and learning that's grounded in real-world experience. Our workshop today is designed with this view in mind. Speaker notes
  • 9. Suggestions for learning Don't treat this as a drill, we're making something real Don't get discouraged, struggle leads to mastery Don't be shy, take full advantage of our support 5
  • 10. To get the most out of this class, we have three suggestions for getting the most our of this experience. The first suggestion is to realize we're building something real and accept that's going to be messy. There will be many right answers and a good project is never done. There will always be ways you can make it better. Whatever your level, we're going to push you so it's a little hard. Even basic addition was hard at one point. Struggle is a part of mastery. Try not to get discouraged. Finally, we're here to help. Take advantage of that support, make sure to ask questions during lecture when you're confused. Make sure you call your TA when you need help. When coding, be resourceful. Always! Speaker notes
  • 11. This is what we're making 6
  • 12. Today we're building a simple virtual pet. We can click three different buttons to feed our pet, play with our bet, and have our pet do some exercise. When we click on these buttons, we'll increase or decrease the weight or happiness of our pet. Speaker notes
  • 13. Agenda Starter code review (5 min) Learn key Javascript concepts (25 min) Build your app! (40 min) Go over solutions (10 min) Next steps (10 min) 7
  • 14. I’ll start by walking you through the HTML/CSS starter code so you have a reference of what you’ll be working with. Then I’ll go over important Javascript concepts that you’ll need to complete the app. You’ll then build the app during which time the TA’s and myself will be walking around to help you guys out. At the end we’ll go over solutions and then cover next steps for continuing your learning. Speaker notes
  • 16. Go ahead and go to this url to get the starter code. We’re using a online code editor called Glitch which will let us see the result of our code really quickly. On the README.MD file you should see an overview of the project and the challenges you'll need to complete. The files we’ll be using today on the left are client.js and index.html. You can ignore style.css, server.js, package.json and .env. At the bottom of the Readme file we've added some helpful links for further help on particular concepts. Lets look at the index.html file to see how our app is structured. We have an image which includes a picture of our pet. We're displaying the pet's name, weight, and level of happiness. Below that are three buttons. One to give the pet a treat, increasing it's weight and happiness. One is to play with our pet, decreasing it's weight and increasing it's happiness. The third is exercise which decreases it's weight and happiness. All of the code you’ll be writing will be in client.js but you may need to refer to the html and css file to solve some of the problems. Once you’ve written some code, click the “Show Live” button at the top to open a new tab that will automatically update as you edit your code. Speaker notes
  • 17. Defining a variable with Javascript var firstVariable = 20 Initialize variable Name of variable Value of variable 9
  • 18. Let's start with reviewing variables in Javascript. Variables let us assign some value to a a string. We use variables to store information that we'll use when our app is running. To define a variable in Javascript, we start with the keyword "var". We then give our variable a name. The name should start with a letter. Try to make sure your variable names are descriptive. It's ok if they are long. Then we set that variable name equal to some value. That value can be any data structure in JS including numbers and strings. Speaker notes
  • 20. Alright lets try writing this out. Add var firstVariable = 20. If we type firstVariable now, what is going to happen? The number 20 is stored in the variable so every time we use that variable, we're referring to the 20. With a number, we can also increment or decrement that number. Once we define the variable, we can re-define it as either more or less. So we could do firstVariable = firstVariable + 1 to change our variable from 20 to 21. In this way, an equal sign in JS is different than in math. A single equal sign means we're assigning a value, not saying two things are equal. What other things can we store in a variable? In Javascript we can store pretty much everything in a variable. We can store booleans and strings as well. Lets see examples of each of those. Instead of a number, set firstVariable equal to a string. In JS, when we put a value in quotes, it assumes its a string. Let's console.log the string. We can do the same with booleans. Speaker notes
  • 21. Introducing our pet "object" Name "Thinkpup" Weight 6 Happiness 0 11
  • 22. Lets say we want to store a bunch of different information in one variable, we can do that with a Javascript object. We'll be using a JS object remember all the aspects of our virtual pet. An object will basically have a list of "keys" and "values". So we can store all the information about our pet in one place. In this case, we'll have three items in our "list". The name of our pet, which would be a string. The weight which would be a number. And how happy they are, which will also be a number. We can "get" and "set" our values by grabbing them from the object with the "key" which is always a string. In this case, our key for "Thinkpup" is "name". Speaker notes
  • 24. Creating an object Define an object with curly brackets. The "key" is always a string. The value can be whatever value we like. A Javascript object can hold all sorts of values in one variable. Retrieving a value We can retrieve a value by saying pet_info.name or pet_info['name'] Changing a value We can change a value by saying pet_inf['name'] = "Nala" Speaker notes
  • 26. A function lets you separate your code into bite-sized pieces which you can use over again. When you write a function to use later, you are “declaring” it. When you use (or run) that function you are “calling” it. To call a function, we simply write doSomething() and then the function is run. Speaker notes
  • 27. If, then, else pet is hungry feed it go to park if true if false 14
  • 28. In all programming languages there exist a way to tell the computer that if X happens, do this, if y happens, do that. In Javascript we use if, then, else statement. So we tell the computer, if this condition is true, say the pet is hungry, feed it. If it's not hungry (or that condition is false), go to the park. After this, continue running the program. Speaker notes
  • 30. This is how we'd write that concept in Javascript. We have an "if" keyword and then some condition that could either be True or False in parentheses. If it's true, it would run the code in the first bracket. If it's not true, we'd run the code in the else block. Speaker notes
  • 31. Real developers use Google... a lot 16
  • 32. With that you should be ready to start the challenges. One last note before we do the first challenge together. Google is an everyday part of being a developer. A key part of becoming a developer is getting comfortable using Google to learn and look up things. The more you code, the more you will use Google, not the other way around. Speaker notes
  • 33. Let's work on the first step together http://bit.ly/tf-virtual-pet 17
  • 34. Alright, with that let's start building our app. On the left, you can see the files you'll be working on. The Readme will give you instructions. You'll be writing your code in client.js. You shouldn't need to touch any of the other files. After you write your code, it will automatically be saved. At any point you can hit "Show Live" to see a live version of your app. Let's start the first step together. So in this first step, we want to create our pet_info object with three keys. How would we do that? Feel free to name your pet whatever you like and set it's starting happiness and weight to whatever you like. (Assign TA's to different sections of class) Speaker notes
  • 36. Alright. Let's go over the solutions to the main challenges. For each of the functions, we're going to do a version of the same thing. We're going to first grab the value from our object and then assign it to that value plus or minus some number. For our third step, we want to make sure weight can't go below zero. To do this, we add a function that checks weight before we update it in the HTML. If weight is below one, it should equal one. Speaker notes
  • 37. Ways to keep learning 19
  • 38. Thinkful's Free Resource HTML, CSS and JavaScript Unlimited mentor-led Q&A sessions Personal Program Manager OnlyOnly availableavailable during this eventduring this event bit.ly/webdev-sd 20