Permalink
Browse files

Project 3.

  • Loading branch information...
mmpessoa committed May 1, 2012
1 parent 006e248 commit 1f8cdb673c517dbcefaea2292463065196a8b820
View
BIN .DS_Store
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,18 @@
+Project 3 requirements:
+
+For your project you are required to have at least some JSON data. Since JSON is a subset of JavaScript literal values, even a single variable of any type is technically JSON. However, for the purpose of this project, the JSON requirement is as follows:
+The top level (outermost) data type must be an object or array.
+There must be at least two levels of additional types beneath the top level type, for a total of at least 3 levels of data. That is, you may have an object that has an array of objects, or an object with an array of arrays, or an array with objects within objects, etc.
+At the innermost level you will have the primitive data types: strings, numbers, and booleans.
+For example, I might have a pirate object, with a ships array property, where each item was an object with properties such as shipName, cargoSpace, etc. There are three levels (pirate→ships→ship) and primitive data at the lowest level.
+
+
+For your project you have been given a number of flowchart elements without connectors between them. As you write your code to create a cohesive application out of those basic parts, you will also need to create a flowchart that represents your code by including those building blocks along with the connectors and annotations necessary to make a sensible chart.
+
+
+Your project does not require any private properties or methods, nor do you need to follow the module pattern in your code.
+
+This assignment is in 3 parts: JavaScript code, Google Drawing flowchart, and Git repository.
+You are open to code any story you want, as long as you can use (at least) all of the elements in that flowchart. Don't worry if some of the symbols are new—they will be covered in this week's activities.
+This part of the assignment is graded on your syntax, coding style, functionality, and feature completeness. You may refactor your Deliverable 1 or Deliverable 2 code, so you don't have to start fresh. You may reuse your theme, or come up with a new one.
+
View
@@ -0,0 +1,136 @@
+/*
+
+Michele M. Pessoa
+19 January 20112
+JSON data file for Deliverable 3
+
+*/
+
+
+//This object contains an array that contains three objects.
+
+var json = {
+
+ "pets": [
+
+ {
+ "name": "Beren",
+ "breed": "French Bulldog",
+ "price": 900,
+ "female": false,
+ "color": "brindle",
+ "coat": "short",
+ "shedding": "light",
+ "lifeExpectancy": 12,
+ "size": "small",
+ "description": "polite and mellow.",
+ "trainability": "average"
+},
+
+ {
+ "name": "Freya",
+ "breed": "Bassett Hound",
+ "price": 350,
+ "female": true,
+ "color": "tri-color",
+ "coat": "medium",
+ "shedding": "moderate",
+ "lifeExpectancy": 12,
+ "size": "medium",
+ "description": "loving and eager to please.",
+ "trainability": "stubborn"
+
+},
+
+ {
+ "name": "Cricket",
+ "breed": "Dachshund",
+ "price": 250,
+ "female": true,
+ "color": "black and tan",
+ "coat": "short",
+ "shedding": "light",
+ "lifeExpectancy": 14,
+ "size": "small",
+ "description": "cat-like and sneaky.",
+ "trainability": "stubborn"
+
+
+}
+
+]
+};
+
+
+
+//This object contains an array that contains objects for my favorite breeds.
+
+var json2 = {
+
+ "favoriteBreeds": [
+
+ {
+ "pureBreed": "Dachshund",
+ "congenitalDefects": "thyroid disease"
+ },
+
+ {
+ "pureBreed": "Bassett Hound",
+ "congenitalDefects": "chronic ear infections"
+ },
+
+ {
+ "pureBreed": "French Bulldog",
+ "congenitalDefects": "heatstroke"
+ },
+
+ {
+ "pureBreed": "Miniature Schnauzer",
+ "congenitalDefects": "renal dysplasia"
+ },
+
+ {
+ "pureBreed": "Pembroke Welsh Corgi",
+ "congenitalDefects": "disk disease"
+ }
+
+ ]
+
+};
+
+
+
+//This object contains an array that contains objects for the puppy sale.
+
+var json3 = {
+
+ "puppiesOnSale": [
+
+ {
+ "breed": "Boston Terrier",
+ "price": 650,
+ "female": true
+ },
+
+ {
+ "breed": "Pug",
+ "price": 900,
+ "female": true
+ },
+
+ {
+ "breed": "Beagle",
+ "price": 1200,
+ "female": false
+ },
+
+ {
+ "breed": "Shar-Pei",
+ "price": 1600,
+ "female": true
+ }
+
+ ]
+
+};
+
@@ -0,0 +1,149 @@
+/*
+
+Michele M. Pessoa
+19 January 20112
+Deliverable 3
+Theme: Buying a puppy.
+
+*/
+
+
+//Setting up some global string arrays.
+
+var designerDogs = ["Puggle", "Jug", "Mini Hippo", "Ori-Pei"]
+var petStores = ["Puppy City", "Canine Coral Kennels", "Shake-a-Paw", "CitiPups"]
+
+
+
+
+//This procedure displays text without typing "console.log" each time.
+var say = function (message){
+ console.log(message);
+};
+
+//Start the story.
+
+say("I\'ve had three wonderful dogs in my life:");
+
+
+
+
+//This function pulls in data from the JSON file.
+var handleData = function (jsonData){
+ console.log(jsonData);
+};
+
+
+
+
+
+//This function pulls in data from the JSON file and describes each of my pet dogs.
+var displayDogs = function (jsonData) {
+ for (var i=0; i<json.pets.length; i++) {
+ var dog = json.pets[i];
+ console.log( dog.name + ", my " + dog.breed + ", was very " + dog.description);
+ };
+};
+
+
+displayDogs(json);
+
+
+//This is a number function returning the product of an argument times 7 to calculate "dog years."
+
+function calculateDogYears(aNumber) {
+ return aNumber*7;
+ };
+
+
+say("Beren recently passed away from cancer. It was especially sad, since he was only 8 years-old, or " + calculateDogYears(8) + " dog years.");
+
+
+
+//This function takes in a number array and calculates the average
+
+Array.prototype.sum = function() {
+for (var i = 0, L = this.length, sum = 0; i < L; sum += this[i++]);
+return sum;
+}
+
+var lifeSpan = [15, 12];
+
+var ave = ( (lifeSpan.sum())/lifeSpan.length );
+
+
+//Continue story
+
+say( "My previous two dogs, Cricket and Freya, lived an average of " + ( ave ) + " years, or " + calculateDogYears(ave) + " dog years." );
+say("I\'m looking for a new puppy, but the choices are overwhelming.");
+say("I like the following purebred dogs, but each breed is susceptible to some serious congenital defects: ");
+
+
+//This function matches the breeds with their congenital defects.
+
+var displayDefects = function (json2Data) {
+ for (var i=0; i<json2.favoriteBreeds.length; i++) {
+ var dog2 = json2.favoriteBreeds[i];
+ //return( dog2.pureBreed +"s: " + dog2.congenitalDefects);
+ console.log( dog2.pureBreed +"s: " + dog2.congenitalDefects);
+ };
+};
+
+displayDefects(json2);
+
+
+
+
+
+//Continue telling the story.
+say("So far I\'ve visited " + petStores.length + " stores in an effort to find a puppy. My budget is $2,000. I want a small or medium sized female puppy. I know that I don\'t want a Boston Terrier. I would prefer one of the previously mentioned purebred ddogs.");
+say("However, at " + petStores[2] + " I was introduced to some very cute crossbred dogs that I hadn\'t previously considered:");
+
+var i=0;
+while (i<designerDogs.length) //This loop lists the Designer Dogs.
+{
+
+ console.log(designerDogs[i] + "s");
+ i++;
+};
+
+
+//This string function concatenates a prefix and a suffix to create a "Designer Dog" name.
+
+var designerDogName = function (prefix, suffix) {
+ //console.log(prefix+suffix);
+ return (prefix+suffix);
+};
+
+//Continue telling the story.
+
+console.log ("Many crossbred, or \"Designer Dogs\" derive their unique names by splicing the names of its sire\'s and dam\'s breeds together. For example, a Shih Tzu and Poodle mix is called a " + designerDogName("Shi", "Poo") + ".");
+
+
+say("About a week after visiting the stores I received an email from " + petStores[3] + " with some information about puppies on sale:")
+
+
+
+//This function uses JSON data to show if a puppy fits the purchase criteria.
+
+var purchasePuppy = function (json3Data) {
+ for (var i=0; i<json3.puppiesOnSale.length; i++) {
+ var dogSale = json3.puppiesOnSale[i];
+
+ var myBudget= 2000;
+ if (dogSale.breed != "Boston Terrier" && dogSale.price <= myBudget && dogSale.female == true){
+ //console.log("This puppy is a possibility. She matches my wishlist for price, gender and breed.");
+ console.log("There is a " + dogSale.breed + " puppy available for $" + dogSale.price + ". This puppy is a possibility. It matches my wishlist for price, gender and breed.");
+
+ }
+else
+ console.log("There is a " + dogSale.breed + " puppy available for $" + dogSale.price + ". I shouldn\'t buy this puppy. It doesn\'t fit all of my criteria.");
+};
+
+
+};
+
+purchasePuppy(json3);
+
+
+say("In the end, I really fell in love with a Mini Walrus puppy, a cross between a Shar-Pei and a Bassett Hound. Unfortunately, the last one was sold. I think I\'ll hold out and wait for a female to become available.");
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Michelle M. Pessoa :: Project 3 :: SDI-1201</title>
+ <link rel="stylesheet" href="sdi.css" type="text/css" />
+</head>
+<body>
+<header>
+ <h1>SDI-1201: Michelle M. Pessoa</h1>
+ <h2>Project 3</h2>
+</header>
+<article>
+<p>My project's theme is an exploration of the process of purchasing a new puppy.</p>
+<p>I am interested in purebred dogs such as Corgis, Dachshunds and French Bulldogs, but I'm also considering crossbred dogs such as the Mini-Walrus (a Shar-Pei / Bassett Hound mix) or a Mini Bulldog (an English Bulldog / Boston Terrier mix). I am not interested in purchasing a large dog -- small or medium is fine. The dog needs to have a life expectancy of at least 10 years, and it needs to be female. The budget for the puppy is $2,000. </p>
+</article>
+<footer>
+ <p>19 January 2012, Michelle M. Pessoa</p>
+</footer>
+<script type="text/javascript" src="json.js"></script>
+<script type="text/javascript" src="pessoa_michelle_assignment3.js"></script>
+</body>
+</html>
View
@@ -0,0 +1,34 @@
+html {
+ background-color: #E1DFD3;
+}
+body {
+ font-family: "Lucida Grande", "Arial", sans-serif;
+ margin: 1.5em auto;
+ padding: 1.5em;
+ background-color: white;
+ color: #4D4B39;
+ max-width: 35em;
+ border: 0.75em solid #A6A59C;
+ line-height: 1.5em;
+}
+p {
+ margin: 1.5em 0;
+}
+h1 {
+ background-color: #4D4B39;
+ color: #E1DFD3;
+ font-size: 200%;
+ padding: 0.75em;
+ margin: -0.75em -0.75em 0.75em -0.75em;
+}
+h2 {
+ background-color: #4D4B39;
+ color: #88a75d;
+ font-size: 150%;
+ padding: 1em;
+ margin: -1em -1em 1em -1em;
+}
+h1 + h2 {
+ margin-top: -1em;
+ padding-top: 0;
+}

0 comments on commit 1f8cdb6

Please sign in to comment.