qq_白首不相离_8
2019-03-27 21:29
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系好安全带,准备启航</title>
<script type="text/javascript">
//通过javascript的日期对象来得到当前的日期,并输出。
var date=new Date();
var year=date.getFullYear()+"年";
var month=date.getMonth()+"月";
var date1=date.getDate()+"日";
//alert(date1);
var weekq=["星期一","星期二","星期三","星期四","星期五","星期六","星期天"];
var week=weekq[date.getDay()];
//alert(week);
var xinxi="小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小五:76;小迪:64;小曼:76";
var fenshu=[xinxi.slice(3,5),xinxi.slice(9,11),xinxi.slice(15,17),xinxi.slice(21,23),xinxi.slice(27,29),xinxi.slice(33,35),xinxi.slice(39,41),xinxi.slice(45,47),xinxi.slice(51,53),xinxi.slice(57,59)];
// alert(fenshu);
var sum=0;
for(var i=0;i<fenshu.length-1;i++){
sum=sum+parseInt(fenshu[i]);
}
//alert(sum);
var avg=sum/fenshu.length;
document.write(year+month+date1+" "+week+"---班级平均分为"+avg+" ."+"总分为:"+sum);
</script>
</head>
<body>
</body>
</html>
兄弟 你的循环在网页能运行出来 我的就悲剧了 运行循环就卡死了 只能写好多代码了 分享一下
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系好安全带,准备启航</title>
<script type="text/javascript">
//通过javascript的日期对象来得到当前的日期,并输出。
var date=new Date();
var year=date.getFullYear();
var month=date.getMonth();
var day=date.getDay();
var Weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
var weekday=Weekday[date.getDay()];
document.write(year+"年"+month+"月"+day+"日"+" "+weekday);
//成绩是一长窜的字符串不好处理,找规律后分割放到数组里更好操作哦
var scoreStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76";
var score1=parseInt(scoreStr.substr(3,2));
var score2=parseInt(scoreStr.substr(9,2));
var score3=parseInt(scoreStr.substr(15,2));
var score4=parseInt(scoreStr.substr(21,2));
var score5=parseInt(scoreStr.substr(27,2));
var score6=parseInt(scoreStr.substr(33,2));
var score7=parseInt(scoreStr.substr(39,2));
var score8=parseInt(scoreStr.substr(45,2));
var score9=parseInt(scoreStr.substr(51,2));
var score10=parseInt(scoreStr.substr(57,2));
document.write("--班级总分为:"+Math.floor((score1+score2+score3+score4+score5+score6+score7+score8+score9+score10)/10));
//从数组中将成绩撮出来,然后求和取整,并输出。
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>系好安全带,准备启航</title> <script type="text/javascript"> //通过javascript的日期对象来得到当前的日期,并输出。 var Udate =new Date(); var weekday=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]; document.write('今天是:'); document.write(Udate.getFullYear()+'年'); document.write((Udate.getMonth()+1)+'月'); document.write(Udate.getDate()+'日 '); document.write(weekday[Udate.getDay()]+'<br>'); //成绩是一长窜的字符串不好处理,找规律后分割放到数组里更好操作哦 var scoreStr = "小明:87;小花:81;小红:97;小天:76;小张:74;小小:94;小西:90;小伍:76;小迪:64;小曼:76"; scoreStr1=scoreStr.split(';'); //如果没写参数 ,则会变成只有一个 整个字符串元素的列表 var sum=0; // sum 要在for外面定义 要不然会一直赋值 for(var i=0;i<scoreStr1.length;i++) { var num = scoreStr1[i].substring(3, 5); document.write(num+'<br>'); sum+=parseInt(num); } document.write(sum); var average=parseInt(sum/scoreStr1.length); //parseInt也可以来取整 document.write('这个班的平均分是:'+average); //从数组中将成绩撮出来,然后求和取整,并输出。 </script> </head> <body> </body> </html>
JavaScript进阶篇
468194 学习 · 21891 问题
相似问题