The basic use of (shallow) function is called

Today is the first day of the second week I learned of JavaScript. Today, learning the basic functions of the application, the following is a small example of the use of the word several functions, we hope the exhibitions! ! !
Example 1, individual packages cumulative sum function
Let's look at the code:

function wjt(min , max){
                var sum = 0;                
                for(var a = min;a <= max;a++){
                                    sum += a;                 
                }                
                return sum;             
}           
document.write(`${wjt(1 , 1000)} <br>`  );

First of all, we have to distinguish between the functionArguments and parameters. In the above code parameter which is the == function wjt (min, max) == inside this partwjtValue. Document.write argument is the == ( ${wjt(1 , 1000)} <br>); == inside thiswjt. Here I talk about my understanding of them, ha! I feel like parameter inside the companymanagerThis post, whether or not people go when this post are there. The argument is that those of us who, no matter who is to become the manager, are possible (the premise is the individual). Really I do not understand also can be understood, that is: the form to see the unknown x, which in itself is no value, we need to give it a specific value. That is our argument it!
Here is our operating results with:

Here Insert Picture Description

2, leap year judging function: input year, the return value is a leap year leap year or
see the code:

function fun1(number){
                var a;                
                if(number % 400 == 0 || number % 4 == 0 && number % 100 != 0){                    
                	a = "闰年。"                
                }else{                    
                	a = "平年。"                
                }                
                return a;          
}            
document.write(`${fun1(1999)} <br>`);

Look at the screenshot:
Here Insert Picture Description

3, a prime number is determined: the input value, the return value is a prime number / composite numbers
see Code:

function fun2(move){
        var c = '质数。';    
        for(b = 2;b <= move - 1;b++){
                if(move % b == 0){            
                	c = '合数。';            
                	break;        
                }    
         }
         return c;
}
document.write(`${fun2(3)} <br>`);

Screenshot below:
Here Insert Picture Description

4, it is determined whether the input content is a string, if so, the return value is true, and if not, the return value is false
code is as follows:

function fun3(lol){
                var d;                
                if(typeof(lol) == "String"){
                                    d = "true"                
                                    }else{
                                           d = "false"
                                         }               
                                          return d;            
}            
document.write(`${fun3("我是你爸爸")} <br>`);

Screenshot below:
Here Insert Picture Description

Well, by the above four questions, we realized that something?
I'd share with you a small coup Oh! ! !
If we write a function relatively confused, we can put the normal write code that is written in this way, for example, the fourth question: look:
Here Insert Picture Description

This code is no form before the function definition. We then define a function to it:function fun3(lol){}
Our function name is called fun3. andlol Is our function's argument here is Parameter. Copy and paste the code to our {} == == which, remember, we also have a return value, no doubt will certainly be added to that layer functions. We want to return and which value it? ? ? It returns the value of what we want. Finally, our argument is to write the document.write () inside.

This sharing it on here! White one, hope a lot of advice! ! !

Published 10 original articles · won praise 11 · views 445

Guess you like

Origin blog.csdn.net/Anber_wang/article/details/104912802