function get_order(array){ for(var i = 0; i <array.length-1; i++){ for(var j = 0; j < array.length - 1 -i; j++){ if(array[j] < array[j+1]){ var tem = array[j]; array[j] = array[j+1]; array[j+1] = tem; } } } return array; } console.log(get_order([5,7,10,2,15,1,91]));
function max(a,b){ return a > b ? a : b; } var a = prompt('请输入第1个数')-0; var b = prompt('请输入第2个数')-0; alert(max(a,b));
function get_year(year){ if(year % 4 == 0 && year % 100 != 0 || year % 100 == 0){ return true; }else { return false; } } var year = prompt('输入年份'); if(Number(get_year(year)) == 1){ alert('闰年'); }else{ alert('不是闰年'); }
function get_day(year,month,day){ var sum1=0,sum2=0;sum3=0,sum=0; for(var i = 1; i < month; i++){ if(i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) { sum1 = sum1 + 31; }else if (i == 4 || i == 6 || i == 9 || i == 11) { sum2 = sum2 + 30; }else { sum3 = 28; } } sum = sum1 + sum3 + sum2 + day; if((year % 4 == 0 && year % 100 != 0 || year % 100 == 0) && month >= 2){ sum += 1; } return sum; } var year = prompt('请输入年份')-0; var month = prompt('请输入月份')-0; var day = prompt('请输入日期')-0; alert("您输入的日期是第:" + get_day(year,month,day) + '天');