Advertisement
Guest User

Untitled

a guest
Oct 25th, 2015
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  function User(Name, Email) {
  2.  
  3.             this.prototype = {
  4.  
  5.                 User : function(Name, Email){
  6.                     this.Name = Name;
  7.                     this.Email = Email;
  8.                     QuizScores = new Array();
  9.                     CurrentScore = 0;
  10.                 },
  11.  
  12.                 saveScore: function (theScoreToAdd) {
  13.                     QuizScores.push(theScoreToAdd);
  14.                     CurrentScore += theScoreToAdd;
  15.                 },
  16.                 showNameAndScores: function () {
  17.  
  18.                     var result = "Name " + Name + " Scores: ";
  19.  
  20.                     if (QuizScores.length == 0) result += "No scores yet."
  21.  
  22.                     for (var i = 0; i < QuizScores.length; ++i) {
  23.  
  24.                         if (i != QuizScores.length - 1)
  25.                             result += QuizScores[i] + ", ";
  26.                         else
  27.                             result += QuizScores[i] + ".";
  28.                     }
  29.  
  30.                     return result;
  31.                 },
  32.                 changeEmail: function (newEmail) {
  33.                     Email = newEmail;
  34.                 },
  35.  
  36.  
  37.             }
  38.         }
  39.  
  40.         User.prototype.constructor = User;
  41.  
  42.         var user1 = new User("Michael", "michael6@gmail.com");
  43.         var user2 = new User("Johnny", "johnny@gmail.com");
  44.         var user3 = new User("Elvis", "TheKing@yahoo.com");
  45.  
  46.  
  47.         function onLoadFunction() {
  48.  
  49.  
  50.             document.getElementById("paragraph1").innerHTML = user1.prototype.showNameAndScores() +
  51.                     "<br>" + user2.prototype.showNameAndScores() + "<br>" + user3.prototype.showNameAndScores();
  52.  
  53.  
  54.  
  55.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement