Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/kasper9n/playground. playground.kasper.space
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041"use strict"//create objectvar player1 = { name: "Fred", score: 10000, rank: 1,};// add propertyplayer1.gameType = "MMORPG";// add methodplayer1.logScore = function() { console.log(this.score)};//call methodplayer1.logScore();
function Player(n,s,r) { this.name = n; this.score = s; this.rank = r;}
Player.prototype.logInfo = function() { console.log("I am" , this.name);}
Player.prototype.promote = function() { this.rank++; console.log("player " + this.name + " promoted to rank " + this.rank);}
var fred = new Player("Fred",1000,2);fred.logInfo();fred.promote();
var bob = new Player("Bob",50,1);bob.logInfo();bob.promote();