SOURCE

//在表达式中调用
function add(a,b){
    return a*b;
}
var yzq=add(9,2)+3;
document.write(yzq+"<br/>");

// <a href="javascript:add">6666666</a>

  var year=parseInt(prompt('请输入你所需要判断的年份'));
    function Runyear(year)
    {
        if(year%4==0&&year%100!=0)
        {
            var Leapyear1=year+"年是闰年";
            alert(Leapyear1); 
        }
        else if(year%400==0)
        {
            var Leapyear2=year+"年是闰年";
            alert(Leapyear2);
        }
        else
        {
            var Leapyear3=year+"年不是闰年";
            alert(Leapyear3);
        }
        
    }
    document.write(Runyear(year));


var a=3,b=5;
function swap(){
    var tmp;
    tmp=a;
    a=b;
    b=tmp;
}
swap();
document.write("a="+a+",b="+b+"<br/>");


var welcomeString="welcome";
document.write(welcomeString.charAt(2)+"<br/>");
document.write(welcomeString.charAt(6)+"<br/>");

document.write(welcomeString.substring(3)+"<br/>");
document.write(welcomeString.substring(0,6)+"<br/>");

var sentence="fanyikun is big SB!fanyikun";
document.write(welcomeString.replace("come","go")+"<br/>");
document.write(sentence.replace(/fanyikun/g,"SB")+"<br/>");

document.write(sentence.split(" ")+"<br/>");
document.write(sentence.split("")+"<br/>");
document.write(sentence.split(".")+"<br/>");

document.write(sentence.indexOf("class")+"<br/>");
document.write(sentence.indexOf("fanyikun")+"<br/>");
document.write(sentence.lastIndexOf("fanyikun")+"<br/>");
document.write(sentence.match("is")+"<br/>");
document.write(sentence.match(/fanyikun/g)+"<br/>");
document.write(sentence.search(/fanyikun/g)+"<br/>");

function countChar(stringToCount, char) {
    var charCount = 0;
    
    return charCount;
}
var stringToCount = "Can you can a can as a Canner can can a can";
document.write("There are " + countChar(stringToCount, "c") + " c in " + stringToCount); 


var arr=new Array("America","Greece","Britain","Canada","China","Egypt");
    var  count=0;
    //但是这样有一个问题,就是当他一个单词检测到有a或者A之后就不再继续下去了,得到的结果只有4
    function statistic() {
        for (var i=0;i<arr.length;i++){
            if (arr[i].indexOf("a")!=-1 || arr[i].indexOf("A")!=-1){
                count++;
            }
        }
        document.write(count);
    }

    //把这一个字符串又放到一个数组里去查看是否有aA
    function statistic1() {
        var arrs=new Array();
        for (var i=0;i<arr.length;i++){
            //把arr[i]放入arrs这个数组里
            arrs=arr[i];
            //循环遍历arrs这个数组
            for (var j=0;j<arrs.length;j++){
                //indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。如果没有找到匹配的字符串则返回 -1
                if (arrs[j].indexOf("a")!=-1 || arrs[j].indexOf("A")!=-1){
                    count++;
                }
            }
        }
        document.write(count);
    }


    var arr=["a","b","c","d"];
    document.write(arr+"<br/>");
    document.write(arr[2]+"<br/>");
    arr[1]="ss";
    document.write(arr+"<br/>");
    arr[6]="sr";
    document.write(arr+"<br/>");



function getNum(str) 
{
var num = 0;
for (var i = 0; i < str.length; i++) 
{
var char = str.charAt(i);
if (char != " " && !isNaN(char)) 
{
num++;
}
}
return num;
}
document.write(getNum("5646giabifa1564sdafvasf"));

function min(arr){
    var num = arr[0]
    for(var i  = 0 ; i <arr.length;i++)
    {
      if(arr[i]<num)
      {
        num = arr[i]
      }
    }
    return num;
  }
  var arr = [3,9,6,4,100];
  document.write(max(arr)+'</br>');  // 最大
  document.write(min(arr)+'</br>');  // 最小
var a=prompt("请输入任意4个数字","1,5,8,7").split(",");
var min=max=a[0];
for(var i=0;i<a.length;i++)
{ if(a[i]>max) max=a[i];
if(a[i]<min) min=a[i];
}
alert("最小值:"+min+","+"最大值:"+max);
function max(arr){
    var num = arr[0]
    for(var i  = 0 ; i <arr.length;i++)
    {
      if(arr[i]>num)
      {
        num = arr[i]
      }
    }
    return num;
  }
console 命令行工具 X clear

                    
>
console