Home > Net >  How to only access seccond parameter?
How to only access seccond parameter?

Time:01-04

I'm create a function and assigned two-parameter But For this assigned two-argument. I want to control one parameter right side [para2]

let veri=2;
function school(para1,para2)     // if para2 accept 
{
    para2=Math.floor(Math.random()*para2); //so :- 0 or 1
    return para2;
}
veri=school(veri);     // ! This veri pass arg second parameter
 if(veri){
   console.log('Time is playing cricket');
 }else{
   console.log('study time...');
 }

We have to pass two arguments for two parameters I want that only one argument should be passed and only the right side can be controlled.

CodePudding user response:

One of the things you should pay attention to is the "syntax" of a programming language (Or frankly, any programming language).

When you are defining a function, or essentially a block of code with a specific scope, a name and parameters, you are basically saying how it should work and what it should do. Hence, defining a function with two parameters, you should consider the first parameter as well. Because you have defined it as such.

Now there are many ways to approaching this.

You can either give it a meaningless value:

school(undefined, veri)
// OR
school(0, veri)
// OR
school('Nothing to do here', veri)

Or inside the body of the function define distinct values that the function will not act upon.

But because there is a second parameter, you can't neglect it when you're calling your function.

CodePudding user response:

In your case you can pass undefined as the first arg, e.g.

school(undefined, veri)

CodePudding user response:

To skip parameter 1, pass in undefined

veri=school(undefined, veri); 
  • Related