Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. var canyonCows = [
  12. {name: "Bessie", type: "cow", hadCalf: "Burt"},
  13. {name: "Donald", type: "bull", hadCalf: null},
  14. {name: "Esther", type: "calf", hadCalf: null},
  15. {name: "Burt", type: "calf", hadCalf: null},
  16. {name: "Sarah", type: "cow", hadCalf: "Esther"},
  17. {name: "Samson", type: "bull", hadCalf: null},
  18. {name: "Delilah", type: "cow", hadCalf: null}
  19. ];
  20. Array.prototype.countCattle = function(kind) {
  21. var numKind = 0;
  22. for ( var i = 0; i<this.length; i++) {
  23. if (this[i].type == kind) { // IF THIS[ARRAY INDEX "i"].TYPE is equal to == kind then..
  24. numKind += 1; // += (add 1 to...) numKind
  25. }
  26. }
  27. return numKind;
  28. };
  29. </script>
  30.  
  31.  
  32.  
  33. <script id="jsbin-source-javascript" type="text/javascript">var canyonCows = [
  34. {name: "Bessie", type: "cow", hadCalf: "Burt"},
  35. {name: "Donald", type: "bull", hadCalf: null},
  36. {name: "Esther", type: "calf", hadCalf: null},
  37. {name: "Burt", type: "calf", hadCalf: null},
  38. {name: "Sarah", type: "cow", hadCalf: "Esther"},
  39. {name: "Samson", type: "bull", hadCalf: null},
  40. {name: "Delilah", type: "cow", hadCalf: null}
  41. ];
  42. Array.prototype.countCattle = function(kind) {
  43. var numKind = 0;
  44. for ( var i = 0; i<this.length; i++) {
  45. if (this[i].type == kind) { // IF THIS[ARRAY INDEX "i"].TYPE is equal to == kind then..
  46. numKind += 1; // += (add 1 to...) numKind
  47. }
  48. }
  49. return numKind;
  50. };</script></body>
  51. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement