function add(a,b){
return a*b;
}
var yzq=add(9,2)+3;
document.write(yzq+"<br/>");
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;
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);
}
function statistic1() {
var arrs=new Array();
for (var i=0;i<arr.length;i++){
arrs=arr[i];
for (var j=0;j<arrs.length;j++){
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