1. 写一个函数,能返回传入的任意两个数字的最大值。
2. 写一个函数,能返回传入的任意三个数字的最大值。
3. 写一个函数,能判断传入的一个数值是否是质数,如果是质数返回true,如果不是质数返回false,(质数:从2开始只能被1和自身整数的数)
4. 写一个函数,能翻转传入的任意数组,并把翻转结果通过返回值返回。(要求自己实现,不能调用数组方法)
5. 写一个函数,能对所有传入的数组按照从小到大进行排序,并把排序结果通过返回值返回
6. 利用递归函数完成斐波那契数列
由于 已经完成,先放成果图。
代码如下
<!DOCTYPE html>
< html lang = " en" >
< head>
< meta charset = " UTF-8" >
< meta name = " viewport" content = " width=device-width, initial-scale=1.0" >
< title> Document</ title>
</ head>
< body>
< div>
请输入你的成绩:
< input type = " text" name = " socore" id = " a" style =" width : 100px; height : 20px; " >
< button id = " btn" onclick = " jungle()" > 提交</ button>
</ div>
< div>
请输入俩个数:
< input type = " text" name = " " id = " b" value = " " style =" width : 50px; height : 20px; " >
< input type = " text" name = " " id = " c" value = " " style =" width : 50px; height : 20px; " >
< button id = " btn" onclick = " compare()" > 比较</ button>
</ div>
< div>
请输入三个数:
< input type = " text" name = " " value = " " id = " d" style =" width : 30px; height : 30px; " >
< input type = " text" name = " " value = " " id = " e" style =" width : 30px; height : 30px; " >
< input type = " text" name = " " value = " " id = " f" style =" width : 30px; height : 30px; " >
< button id = " btn" onclick = " compareT()" > 比较</ button>
</ div>
< div>
< input type = " text" name = " " value = " " id = " g" style =" width : 100px; height : 20px; " >
< button id = " btn" onclick = " zhishu()" > 判断</ button>
</ div>
< div>
< input type = " text" name = " " value = " " id = " h" style =" width : 100px; height : 20px; " >
< button id = " btn" onclick = " sort()" > 开始倒置</ button>
</ div>
< div>
< input type = " text" id = " i" style =" width : 100px; height : 20px; " >
< button onclick = " sortArray()" > 开始排序</ button>
</ div>
< div>
请输入数列的长度:
< input type = " text" id = " j" style =" width : 20px; height : 20px; " >
< button onclick = " sortF()" > 开始创建斐波那契数列〉〉〉</ button>
</ div>
< script type = " text/javascript " > javascript">
function jungle ( ) {
var a= document. getElementById ( "a" ) . value;
if ( a>= 0 && a<= 59 ) {
alert ( "不及格!" )
} else if ( a>= 60 && a<= 79 ) {
alert ( "及格!" )
} else if ( a>= 80 && a<= 89 ) {
alert ( "良好!" )
} else if ( a>= 90 && a<= 99 ) {
alert ( "优秀!" )
} else if ( a== 100 ) {
alert ( "完美!" )
} else {
alert ( "请输入正确的值!" )
}
}
function compare ( ) {
var a= document. getElementById ( "b" ) . value;
var b= document. getElementById ( "c" ) . value;
if ( a> b) {
alert ( a) ;
} else {
alert ( b) ;
}
}
function compareT ( ) {
var a= document. getElementById ( "d" ) . value;
var b= document. getElementById ( "e" ) . value;
var c= document. getElementById ( "f" ) . value;
console. log ( a) ;
console. log ( b) ;
console. log ( c) ;
if ( a< b) {
a= b;
}
if ( a< c) {
a= c;
}
alert ( a) ;
}
function zhishu ( ) {
var a= document. getElementById ( "g" ) . value;
var flag= true ;
for ( var i= 2 ; i< a; i++ ) {
if ( a% i== 0 ) {
alert ( "该数不是质数!" ) ;
flag= false ;
break ;
}
}
if ( flag) {
alert ( "该数是质数!" )
}
}
function sort ( ) {
var a= document. getElementById ( "h" ) . value;
var b= a. split ( " " ) ;
var c= new Array ( b. length) ;
for ( var i= 0 ; i< b. length; i++ ) {
c[ i] = parseInt ( b[ i] ) ;
}
var d= new Array ( c. length) ;
for ( var i= 0 ; i< c. length; i++ ) {
d[ i] = c[ c. length- i- 1 ] ;
}
alert ( d) ;
}
function sortArray ( ) {
var a= document. getElementById ( "i" ) . value;
var b= a. split ( " " ) ;
var c= new Array ( b. length) ;
for ( var i= 0 ; i< b. length; i++ ) {
c[ i] = parseInt ( b[ i] ) ;
}
for ( var i= 0 ; i< c. length- 1 ; i++ ) {
for ( var j= 0 ; j< c. length- i- 1 ; j++ ) {
if ( c[ j] > c[ j+ 1 ] ) {
var t= c[ j] ;
c[ j] = c[ j+ 1 ] ;
c[ j+ 1 ] = t;
}
}
}
alert ( c) ;
}
function sortF ( ) {
var n= document. getElementById ( "j" ) . value;
var array= new Array ( n) ;
function s ( n) {
if ( n== 3 ) {
return 3 ;
} else if ( n== 2 ) {
return 2 ;
} else if ( n== 1 ) {
return 1 ;
} else {
return s ( n- 1 ) + s ( n- 2 ) ;
}
}
for ( var i= 0 ; i< n; i++ ) {
array[ i] = s ( i+ 1 ) ;
}
alert ( array) ;
}
</ script>
</ body>
</ html>