Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. class Persons {
  2.  
  3. constructor(name, surname, age, inRelation, imgURL) {
  4. this.name = name;
  5. this.surname = surname;
  6. this.age = age;
  7. this.inRelation = inRelation;
  8. this.imgURL = imgURL;
  9. }
  10.  
  11.  
  12. // Method to class Persons
  13. render() {
  14. let msg = `
  15. <div class="ppl">
  16. <img src = "${this.imgURL}">
  17. <p>Name: <h3>${this.name}</h3></p>
  18. <p>Surname: <h3>${this.surname}</h3></p>
  19. <p>Age: <h3>${this.age}</h3></p>
  20. <p>Gender: <h3>${this.constructor.name}</h3></p>
  21. <p>In relationship: <h3>${this.inRelation}</h3></p>
  22. <p><a href="#" class = "btn btn-primary" role= "button">Like</a>
  23. <img id = "hearth" src = "img/like.png"></p>
  24. </div>
  25. `;
  26. return msg;
  27.  
  28. }
  29. }
  30.  
  31. // Class for female
  32.  
  33. class Female extends Persons {
  34.  
  35. constructor(name, surname, age, inRelation, imgURL, gender) {
  36. super(name, surname, age, inRelation, imgURL);
  37. this.gender = gender;
  38. }
  39.  
  40. // Overwrite the method
  41.  
  42. reder() {
  43. let msg = `
  44. <div class="ppl">
  45. <img src = "${this.imgURL}">
  46. <p>Name: <h3>${this.name}</h3></p>
  47. <p>Surname: <h3>${this.surname}</h3></p>
  48. <p>Age: <h3>${this.age}</h3></p>
  49. <p>Gender: <h3>${this.gender}</h3></p>
  50. <p>In relationship: <h3>${this.inRelation}</h3></p>
  51. <p><a href="#" class = "btn btn-primary" role= "button">Like</a>
  52. <img id = "hearth" src = "img/like.png"></p>
  53. </div>
  54. `;
  55. return msg;
  56.  
  57.  
  58. }
  59. }
  60.  
  61. // Class for male
  62.  
  63. class Male extends Persons {
  64.  
  65. constructor(name, surname, age, inRelation, imgURL, gender) {
  66. super(name, surname, age, inRelation, imgURL);
  67. this.gender = gender;
  68. }
  69.  
  70. // Overwrite the method
  71.  
  72. reder() {
  73. let msg = `
  74. <div class="ppl">
  75. <img src = "${this.imgURL}">
  76. <p>Name: <h3>${this.name}</h3></p>
  77. <p>Surname: <h3>${this.surname}</h3></p>
  78. <p>Age: <h3>${this.age}</h3></p>
  79. <p>Gender: <h3>${this.gender}</h3></p>
  80. <p>In relationship: <h3>${this.inRelation}</h3></p>
  81. <p><a href="#" class = "btn btn-primary" role= "button">Like</a>
  82. <img id = "hearth" src = "img/like.png"></p>
  83. </div>
  84. `;
  85. return msg;
  86.  
  87.  
  88. }
  89. }
  90.  
  91. // List of people
  92.  
  93. var personCollection = [
  94. new Male("John", "Doe", 30, false, "img/img1.jpg", "Male"),
  95. new Female("Jane", "Doe", 25, false, "img/img4.jpg", "Female"),
  96. new Female("Angelina", "Trump", 20, true, "img/img3.jpg", "Female"),
  97. new Male("George", "Bush", 50, true, "img/img2.jpg", "Male"),
  98. new Male("John", "Doe", 30, false, "img/img1.jpg", "Male"),
  99. new Female("Jane", "Doe", 25, false, "img/img4.jpg", "Female"),
  100. new Female("Angelina", "Fitz", 20, true, "img/img3.jpg", "Female"),
  101. new Male("George", "Bush", 50, true, "img/img2.jpg", "Male"),
  102. ];
  103.  
  104. //Function to show everyone
  105.  
  106. function showAll() {
  107. let bigList = document.getElementById("bigList");
  108. for (var i = 0; i < personCollection.length; i++) {
  109. bigList.innerHTML += personCollection[i].render();
  110. }
  111. }
  112.  
  113. //Function to show only Female
  114.  
  115. function showFemale() {
  116. let bigList = document.getElementById("bigList");
  117. for (var i = 0; i < personCollection.length; i++) {
  118.  
  119. if (personCollection[i].constructor.name == "Female") {
  120. bigList.innerHTML += personCollection[i].render();
  121. }
  122. }
  123. }
  124.  
  125. //Function to show only Male
  126.  
  127. function showMale() {
  128. let bigList = document.getElementById("bigList");
  129. for (var i = 0; i < personCollection.length; i++) {
  130.  
  131. if (personCollection[i].constructor.name == "Male") {
  132. bigList.innerHTML += personCollection[i].render();
  133. }
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement