Reputation: 475
i am trying to write a JavaScript function that takes the parameters and assigns parameter value to a variable...how to do this...
here is what i have tried.....
function getTextWidth(text, fontname, fontsize) () {
var one = text;
var two = fontname;
var three = fontsize;
});
is this correct?
Upvotes: 0
Views: 107
Reputation: 10216
no need for extra ()
function getTextWidth(text, fontname, fontsize) {
var one = text || false,
two = fontname || false,
three = fontsize || false;
if (one) {
}
if (two) {
}
if (three) {
}
});
and then you can call getTextWidth('foobar', 'arial', '12px);
Upvotes: 0
Reputation: 2610
There is no need for var one = text; etc - "text" is already a variable available to your function
Upvotes: 0
Reputation: 44740
The correct syntax is -
function getTextWidth(text, fontname, fontsize){
var one = text;
var two = fontname;
var three = fontsize;
}
Upvotes: 0
Reputation: 103358
You have incorrect syntax. See this for an example of how to declare a function with parameters:
function getTextWidth(text, fontname, fontsize) {
var one = text;
var two = fontname;
var three = fontsize;
}
Upvotes: 1
Reputation: 48547
function getTextWidth(text, fontname, fontsize) {
var one = text;
var two = fontname;
var three = fontsize;
}
You need to remove the extra brackets at the end of your function before the first opening {
. Then you need to remove the trailing bracket and semi-colon. It looks like you are mixing a JavaScript function with jQuery.
Upvotes: 3
Reputation: 15109
Just remove the ()
just before the {
in your function, and replace the });
with };
Upvotes: 0