d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > 500fg Per Javascript Problem
12Next
Add Reply New Topic New Poll
Member
Posts: 20,014
Joined: Mar 28 2009
Gold: 0.02
May 29 2012 11:59pm
Im stuck again. Help guys please. Sorry for so many topics. 500 fg each.



This post was edited by Lightro on May 30 2012 12:01am
Member
Posts: 649
Joined: May 28 2012
Gold: 14.00
May 30 2012 02:02am
500 fg please, thx :

8.

Code

function StrMaker(){
 
  this.str="";
 
  this.add = function(str2){
   this.str = this.str+str2;
  };
 
  this.get = function() {
   return this.str;
  };
 
  this.portion = function(start,end){
   return this.str.substring(start,end);
  };
 
  this.empty = function(){
   this.str="";
  };
 }
Member
Posts: 14,235
Joined: Apr 20 2007
Gold: 15.00
May 30 2012 11:54am
9 here, 500fg pls :)
Code
function extend(first,second){
    for(var propertyName in second){
         if(typeof(second[propertyName]) != "function")
         first[propertyName] = second[propertyName];
    }
    return first;
};


This post was edited by kuzdithom on May 30 2012 12:01pm
Member
Posts: 14,235
Joined: Apr 20 2007
Gold: 15.00
May 30 2012 12:10pm
also 10.

Code
function keys(param){
    var ret = [];
    for(var propertyName in param){
         if(typeof(param[propertyName]) != "function")
              ret.push(param[propertyName]);
    }
    return ret;
};
Member
Posts: 20,014
Joined: Mar 28 2009
Gold: 0.02
May 30 2012 12:32pm
Thanks guys. Now need 2, 6, and 7.




This post was edited by Lightro on May 30 2012 12:36pm
Member
Posts: 649
Joined: May 28 2012
Gold: 14.00
May 30 2012 12:45pm
6.

Code
function Customer(contactName, companyName, address, phoneNumber, eMail){
  this.contactName=contactName;
  this.companyName=companyName;
  this.address=address;
  this.phoneNumber=phoneNumber;
  this.eMail=eMail;
  this.zipCode="";
 
  this.askZip=function(){
   this.zipCode=prompt("Enter zip");
  }
 
  this.get=function(){
  alert(this.contactName+","+this.companyName+","+this.address+","+this.phoneNumber+","+this.eMail+","+this.zipCode);
  }
 }
 
 function test(){
  var c = new Customer("Contact Name","Company Name", "Address", "Phone Number", "Email");
  c.askZip();
  c.get();
 }
Member
Posts: 14,235
Joined: Apr 20 2007
Gold: 15.00
May 30 2012 12:48pm
7.
Code
function clone(obj) {
   var copy = obj.constructor();
   for (var attr in obj) {
       if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
   }
   return copy;
}


teszt:

Code
var a = new Object();
a.prop = 5;
var b = clone(a);;
b.prop = 4;
alert(a.prop);
alert(b.prop);
Member
Posts: 20,014
Joined: Mar 28 2009
Gold: 0.02
May 30 2012 12:49pm
2 left

This post was edited by Lightro on May 30 2012 12:50pm
Member
Posts: 14,235
Joined: Apr 20 2007
Gold: 15.00
May 30 2012 01:07pm
2
Code
Object.prototype.length = function(){
len = 0;
for(var prop in this)
 len++;
return len-2;// not counting the proplength,length function
}
Object.prototype.proplength = function(){
len = 0;
for(var prop in this)
 if(typeof(this[prop]) != "function")
  len++;
return len;
}

var a = new Object();
a.propa = 1;
a.propb = 2;
a.propc = "hello";
a.propd = function(){};
a.prope = false;
a.propf = new Object();

alert(a.proplength());
alert(a.length());
Member
Posts: 1,233
Joined: Apr 9 2007
Gold: 449.04
Jun 3 2012 05:40am
How do you plan on learning if others do all your homework for you? Curious.
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll