From 959ba7607bdf765a6d4784db896d31bb3556a774 Mon Sep 17 00:00:00 2001 From: Laura Watts Date: Wed, 11 Jun 2014 10:49:47 -0700 Subject: [PATCH] Update lauraWatts.js Finished day 2 exercises. Would love feedback from anyone. --- StudentSubmissions/lauraWatts.js | 307 +++++++++++++++++++++++++------ 1 file changed, 255 insertions(+), 52 deletions(-) diff --git a/StudentSubmissions/lauraWatts.js b/StudentSubmissions/lauraWatts.js index 3fb07c9..2ef90e2 100644 --- a/StudentSubmissions/lauraWatts.js +++ b/StudentSubmissions/lauraWatts.js @@ -1,16 +1,146 @@ -// Day 2 +//Use this file to implement Part One of your project + +// 1a +// Create an animal object +var animal = {}; +animal.species = 'canine'; +// console.log(animal.species); +animal['tagline'] = 'Loves sunsets on the beach'; +// console.log(animal['tagline']); +animal.noises = null; +// console.log(animal); + +// 1b +// Create an array of noises (noiseArray) +var noiseArray = []; +noiseArray[0] = 'woof'; +noiseArray.push('grr'); +noiseArray.unshift('whine'); +noiseArray[noiseArray.length] = 'growl'; +// console.log(noiseArray.length); //length is 4 +// console.log(noiseArray.length-1); //last index is 3 +// console.log(noiseArray); + +// 1C +// Assign the noiseArray to our animal's noises property +var noizes = 'noises'; +// console.log(animal[noizes]); +animal[noizes] = noiseArray; +animal['%^&'] = true; +var someVar = 'fur'; +animal[someVar] = true; + +// 2 +// Create an array of animals and add animal-objects to it +// Notice we are using variables to add the objects to the array. The variable name is not part of the objects themselves. +var animals = []; +animals.push(animal); +// console.log(animals); +var quackers = { species: 'duck', tagline: 'Afflack', noises: ['quack', 'honk', 'sneeze', 'growl'] }; +animals.unshift(quackers); +// console.log(animals); + +// Create a couple more animal objects and put them in the animals array +var fluffy = { + species: 'cat', + tagline: 'purr', + noises: [ + 'meow', + 'snort', + 'sneeze', + 'mew' + ] +}; +var elizabeth = { + species: 'turtle', + tagline: 'splash', + noises: [ + 'snap', + 'splash', + 'whatever', + 'mew' + ] +}; +animals.push(fluffy,elizabeth); + +// Step 3 +// Let's think about the best data structure to represent a relationship between two animals in our collection. Imagine that our app has a 'friendslist' on their profile where it lists out all of their friends. What do you think is the best way to represent this? Would you use an array or an object or some combination of both? +// Choose a data structure for the list of friends. Justify your decision. +// ...==> Use an array to name all the friends. You need a collection of some sort and using an object would require you to come up with a property name for each item. +// + +// Create a friends array and add two species to it +// Notice we are not putting animal objects into the friends array. Only a couple strings/species. +var friends = []; +friends.push(fluffy.species, quackers.species); +// console.log(friends); + +// 3b Create a relationships object. +// Add a friends property on the relationships object and set it's value to our friends array +// Add a matches property also, making it an array and populating it with a pair of strings/species as well +var relationships = {}; +relationships.friends = friends; +// console.log(relationships.friends); +// console.log(relationships); // ??????? Why am I getting 'birds' here? +// // friends.push('bird'); +// console.log(friends); + +var matches = []; +// console.log(matches); +relationships.matches = matches; +relationships.matches.push(elizabeth.species, animal.species); +// console.log(relationships); +// console.log(matches); + +//////////////////////////// +// Add a relationships property/object to each animal, setting it equal to our relationships object + +// for (var i=0; i