Advertisement
Guest User

Untitled

a guest
Nov 13th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. function Person(name, surname){
  2. this.name = name;
  3. this.surname = surname;
  4. }
  5. Person.prototype.constructor = function(){
  6.  
  7. };
  8. Person.prototype.getName = function(){
  9. return name;
  10. };
  11. Person.prototype.getSurname = function(){
  12. return surname;
  13. };
  14. Person.prototype.credentials = function(){
  15. return name + " " + surname;
  16. };
  17.  
  18.  
  19. // debugger;
  20. function showMethods(obj){
  21. var methods = [];
  22. var temp = obj.prototype;
  23. for (var id in temp) {
  24. // if (typeof(temp[id]) === "function") {
  25. // methods.push(id.toString());
  26. // }
  27. console.log(temp[id].toString());
  28. }
  29. return methods;
  30.  
  31. }
  32. var customObj = new Person("Bojan", "Filipovski");
  33. console.log(showMethods(Person));
  34. console.log(showMethods(Array));
  35.  
  36.  
  37. //quiz
  38. function User(name, email){
  39. this.name = name;
  40. this.email = email;
  41. this.quizScores = [];
  42. this.currentScore = 0;
  43. }
  44.  
  45. User.prototype.saveScore = function(theScoreToAdd){
  46. this.quizScores.push(theScoreToAdd);
  47. this.currentScore = theScoreToAdd;
  48. };
  49.  
  50. User.prototype.showNameAndScores = function(){
  51. var info = this.name + ": ";
  52. if(this.quizScores.length>0) {
  53. for (var i in this.quizScores) {
  54. info += this.quizScores[i] + ", ";
  55. }
  56. return info.substr(0, info.length - 2)+"</br>";
  57. }
  58. else{
  59. return info += " No Scores Yet"+"</br>";
  60. }
  61. };
  62.  
  63. User.prototype.changeEmail = function(newEmail){
  64. this.email = newEmail;
  65. return this.name + "`s new address is " + this.email;
  66. };
  67.  
  68. // User.prototype.constructor = function(name, email){
  69. // this.name = name;
  70. // this.email = email;
  71. // this.quizScores = [];
  72. // this.currentScore = 0;
  73. // };
  74.  
  75. var user1 = new User("Michael", "michael6@gmail.com");
  76. var user2 = new User("Johnny", "johnny@gmail.com");
  77. var user3 = new User("Elvis", "TheKing@yahoo.com");
  78. user1.saveScore(15);
  79. user1.saveScore(20);
  80. user2.saveScore(10);
  81. user2.saveScore(15);
  82. user2.saveScore(3);
  83. var users = [user1, user2, user3];
  84.  
  85. var winner;
  86. var maxPts = 0;
  87. function printPlayers(){
  88.  
  89. var info = "";
  90.  
  91. for(var i in users){
  92. info += users[i].showNameAndScores();
  93. var currPts = 0;
  94. for(var j in users[i].quizScores){
  95. currPts+= users[i].quizScores[j];
  96. }
  97. if(currPts > maxPts){
  98. maxPts = currPts;
  99. winner = users[i];
  100. }
  101.  
  102. }
  103.  
  104. document.getElementById("players").innerHTML = info;
  105. }
  106.  
  107. function changeEmail(){
  108. var newEmail = document.getElementById("email").value;
  109. if(newEmail != "") {
  110. document.getElementById("emailInfo").innerHTML = user2.changeEmail(newEmail);
  111. }
  112. }
  113.  
  114. function showWinner() {
  115. document.getElementById("winner").innerHTML = "The winner is " + winner.name + " with " + maxPts + " points";
  116.  
  117. }
  118.  
  119. console.log(showMethods(user2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement