When parsing the following argument the console.log states that the two numbers (arguments) are unexpected. Why is this and how could I fix this error?
function max(20, 20) {
return width * height;
}
console.log(max(width, height));
Note the changes:
function max(width, height) //pass 20 to both width and height by calling function this way->> max(20,20);.
{
return width * height;
}
console.log(max(width, height));
//printing width and height
Now,why is function max(20,20) wrong?
variable declaration(or name of a predefined variable),it can not be a value. You had entered 20,20 and 20 is not treated as a variable because variable names cannot begin with a number in javascript and almost all other languages.Well,I know that you are confused because you have seen stuff like max(20,20);. Haven't you? This is called calling the function and passing value to it. I guess this is what you wanted to do.
max(20,20); is a statement in which you are calling the function max. Here (20,20) is valid beacuse you can enter value as well because these values are supposed to be passed to width and height.When you define a function you tell the function the arguments you are going to use ,it is something like defining a variable to use it inside the function.You can't define number as arguments.Try to do it like this:
function max(width , height)
{
return width * height;
}
console.log(max(20, 20));
and pass the numbers you want ,when you use the function ,not when you define it.