Created
November 12, 2015 08:33
-
-
Save goodbedford/e4ae32f5d571e80d53c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// you want to get a new puppy so you go to the puppy palace. you need to print out the list of | |
// all the puppies to make your choice. write a function that will | |
// do loops in three ways and print puppy name,breed and age to each to console. | |
// for loop, while loop, forEach | |
function puppyPrint () { | |
var puppies = [ | |
{name: "ruff", | |
breed: "beagle", | |
age: 1 | |
}, | |
{name: "bunny", | |
breed: "terrier", | |
age: 2 | |
}, | |
{name: "solo", | |
breed: "mix-breed", | |
age: 3 | |
} | |
]; | |
console.log("The For Loop"); | |
//your for loop below | |
for( var i = 0; i < puppies.length; i++){ | |
console.log("name:" + puppies[i].name); | |
console.log("breed:" + puppies[i].breed); | |
console.log("age:" + puppies[i].age); | |
} | |
//your while loop below | |
console.log("The While Loop"); | |
var j = 0; | |
while( j < puppies.length ) { | |
console.log("name:" + puppies[j].name); | |
console.log("breed:" + puppies[j].breed); | |
console.log("age:" + puppies[j].age); | |
j++; | |
} | |
//your forEach below | |
console.log("forEach") | |
puppies.forEach( function(pup){ | |
console.log("name:" + pup.name); | |
console.log("breed:" + pup.breed); | |
console.log("age:" + pup.age); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment