- To work in pairs solving real-world programming problems.
- To understand the basics of building a data backed website.
- To reinforce the foundations of Javascript we've learned so far.
- To learn some new Javascript!
- variables
- looping
- objects
- arrays
- functions
If you don't know any of these concepts, see a Teacher or TA before starting this project!
- open your cloud9 to your portfolio workspace.
- in the terminal run
os installand choose matchy - if asked, input your github username and password
- open the
projects/matchyfolder.
- open the index.html file (double click on it)
- with the index.html file open click the Run button at the top.
- copy the url that appears in your terminal and paste it as the URL of a new tab.
- Go back to your cloud9 and check out the other files in the project.
- Go back to your project's index.html tab
- Open the developer console by right clicking anywhere and choosing
inspect element. - Click on the
consoletab in the panel that opens up.
All work in this section will be done in my_code.js
- Open up my_code.js
- Create a variable named
animaland assign it to an empty object. - Using dot notation give
animala property namedspecieswith a value of any animal species. - Using bracket notation give
animala property callednamewith a value of your animal`s name. - Using either notation, give
animala property callednoiseswith a value of empty array. - run
console.log(animal)and refresh your page to see whatanimallooks like. - It should be something like:
{ species: 'duck', name: 'Jennifer', noises: [] }- Create a variable named
noisesand assign it to an empty array. - Using bracket notation give
noisesit's first element. A string representing a sound your animal might make. - Using an array function add another noise to the end of
noises. - Go to the array documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array?redirectlocale=en-US
- Look through the functions until you find the one that will place an element at the begining of the array.
- Add an element to
noisesusing this function. - Using bracket syntax again, add another element to the end of
noises. Make sure that the way you do this step would work no matter how many elementsnoiseshad. In other words, don't hard code the position of the new element. -
console.logthe length ofnoises -
console.logthe last element innoisesagain without hard coding the index. -
console.logthe whole array. - Does it look right?
- Using bracket syntax, assign the
noisesproperty onanimalto our newnoisesarray. - Using any syntax add another noise to the
noisesproperty onanimal. -
console.loganimal. - Does it look right?
- What are the different ways you can access properties on objects?
- What are the different ways of accessing elements on arrays?
It's super important to give your brain and yourself a rest when you can! Grab a drink and have a think! For like 10 minutes, then, BACK TO WORK! :)
from now on i will say inspect instead of console.log
- Create a variable named
animalsand assign it to an empty array. -
pushouranimalthat we created toanimals. - inspect
animals. What does it look like? - Create a variable called
duckand assign it to the data:
{ species: 'duck', name: 'Jerome', noises: ['quack', 'honk', 'sneeze', 'woosh'] }
-
pushducktoanimals - inspect
animals. What does it look like? - Create two more animal objects each with a species, a name, and at least two sounds sounds and add each one of them to `animals.
- inspect
animals. - inspect the length of
animals - Is everything looking right?
Imagine that our website has a profile page for each animal. On this profile page we can see a list of each animal's friend on the website. Just like how people have a list of friends or followers on facebook or instagram. What would be a good data structure to hold this list of friends?
- Choose a data structure for this list of friends.
- Write a comment in your code that explains why you chose this data structure.
- Create a variable called
friendsand assign it to the data structure that you chose. - Take a look at the documentation for
Math.randomhere: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random - Write a function that takes our
animalsarray and returns a random element usingMath.random - Using this function that you just created, get a random animal and add its
nametofriends. - inspect
friends. - add
friendsas a property namedfriendson one of the animals inanimals - inspect your work.
All work in this section will be done in my_code.js
- Open up
my_code.jsin your editor. - Implement a function called
searchthat:
- Takes 1 paramater, a name of an animal
- Returns the animal's object if an animal with that name exists
- Returns
nullif no animal with that name exists
- Use the search bar at the top of the page to make sure your function works.
- Write a function called
editthat:
- Takes 2 parameters, a name of an animal and an object
- If an animal with that name exists, replace it's entire object with the new object
- Otherwise do nothing
- Test it on the website
- Write a function called
removethat:
- Takes 1 parameter, a name of an animal
- If an animal with that name exists, remove it
- Test that it works on the website
- Write a function called
createthat:
- Takes 1 parameter, an object
- Checks that the object has a
nameproperty with a length > 0 - Checks that the object has a
speciesproperty with a length > 0 - Has a unique name, meaning no other animals have that name
- Adds this new object to the animals array, only if all the other conditions pass.
- Make sure it works
This is called data validation and it's extremely important in web development!
Step back and think about how far you've come!! We are doing really hard stuff and if you've gotten here you get it! This is awesome! It means you are well on your way to becoming a pro web developer. SWEET!