Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- var canyonCows = [
- {name: "Bessie", type: "cow", hadCalf: "Burt"},
- {name: "Donald", type: "bull", hadCalf: null},
- {name: "Esther", type: "calf", hadCalf: null},
- {name: "Burt", type: "calf", hadCalf: null},
- {name: "Sarah", type: "cow", hadCalf: "Esther"},
- {name: "Samson", type: "bull", hadCalf: null},
- {name: "Delilah", type: "cow", hadCalf: null}
- ];
- Array.prototype.countCattle = function(kind) {
- var numKind = 0;
- for ( var i = 0; i<this.length; i++) {
- if (this[i].type == kind) { // IF THIS[ARRAY INDEX "i"].TYPE is equal to == kind then..
- numKind += 1; // += (add 1 to...) numKind
- }
- }
- return numKind;
- };
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">var canyonCows = [
- {name: "Bessie", type: "cow", hadCalf: "Burt"},
- {name: "Donald", type: "bull", hadCalf: null},
- {name: "Esther", type: "calf", hadCalf: null},
- {name: "Burt", type: "calf", hadCalf: null},
- {name: "Sarah", type: "cow", hadCalf: "Esther"},
- {name: "Samson", type: "bull", hadCalf: null},
- {name: "Delilah", type: "cow", hadCalf: null}
- ];
- Array.prototype.countCattle = function(kind) {
- var numKind = 0;
- for ( var i = 0; i<this.length; i++) {
- if (this[i].type == kind) { // IF THIS[ARRAY INDEX "i"].TYPE is equal to == kind then..
- numKind += 1; // += (add 1 to...) numKind
- }
- }
- return numKind;
- };</script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement