Sami Un
Sami Un

Reputation: 9

Javascript- Simple function and object not working

var paper=new Object();
paper.color="red";
paper.height= function(a+b){
return a+b;
}
document.write(paper.height(10,11));

Why's this not working? Someone please explain..

Upvotes: 0

Views: 40

Answers (2)

Kim T
Kim T

Reputation: 6436

function(a+b) should be function(a, b)

var paper = {};
paper.color = "red";
paper.height = function(a, b) {
    return a + b;
}
document.write(paper.height(10, 11));

Upvotes: 0

chsh
chsh

Reputation: 2394

Your function definition is incorrect. "a+b" isn't valid for arguments, you need to comma separate them:

paper.height = function(a,b) { return a + b; };

Upvotes: 1

Related Questions