Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Person(name, surname){
- this.name = name;
- this.surname = surname;
- }
- Person.prototype.constructor = function(){
- };
- Person.prototype.getName = function(){
- return name;
- };
- Person.prototype.getSurname = function(){
- return surname;
- };
- Person.prototype.credentials = function(){
- return name + " " + surname;
- };
- // debugger;
- function showMethods(obj){
- var methods = [];
- var temp = obj.prototype;
- for (var id in temp) {
- // if (typeof(temp[id]) === "function") {
- // methods.push(id.toString());
- // }
- console.log(temp[id].toString());
- }
- return methods;
- }
- var customObj = new Person("Bojan", "Filipovski");
- console.log(showMethods(Person));
- console.log(showMethods(Array));
- //quiz
- function User(name, email){
- this.name = name;
- this.email = email;
- this.quizScores = [];
- this.currentScore = 0;
- }
- User.prototype.saveScore = function(theScoreToAdd){
- this.quizScores.push(theScoreToAdd);
- this.currentScore = theScoreToAdd;
- };
- User.prototype.showNameAndScores = function(){
- var info = this.name + ": ";
- if(this.quizScores.length>0) {
- for (var i in this.quizScores) {
- info += this.quizScores[i] + ", ";
- }
- return info.substr(0, info.length - 2)+"</br>";
- }
- else{
- return info += " No Scores Yet"+"</br>";
- }
- };
- User.prototype.changeEmail = function(newEmail){
- this.email = newEmail;
- return this.name + "`s new address is " + this.email;
- };
- // User.prototype.constructor = function(name, email){
- // this.name = name;
- // this.email = email;
- // this.quizScores = [];
- // this.currentScore = 0;
- // };
- var user1 = new User("Michael", "michael6@gmail.com");
- var user2 = new User("Johnny", "johnny@gmail.com");
- var user3 = new User("Elvis", "TheKing@yahoo.com");
- user1.saveScore(15);
- user1.saveScore(20);
- user2.saveScore(10);
- user2.saveScore(15);
- user2.saveScore(3);
- var users = [user1, user2, user3];
- var winner;
- var maxPts = 0;
- function printPlayers(){
- var info = "";
- for(var i in users){
- info += users[i].showNameAndScores();
- var currPts = 0;
- for(var j in users[i].quizScores){
- currPts+= users[i].quizScores[j];
- }
- if(currPts > maxPts){
- maxPts = currPts;
- winner = users[i];
- }
- }
- document.getElementById("players").innerHTML = info;
- }
- function changeEmail(){
- var newEmail = document.getElementById("email").value;
- if(newEmail != "") {
- document.getElementById("emailInfo").innerHTML = user2.changeEmail(newEmail);
- }
- }
- function showWinner() {
- document.getElementById("winner").innerHTML = "The winner is " + winner.name + " with " + maxPts + " points";
- }
- console.log(showMethods(user2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement