我和友友们一样喜欢编辑,天天敲代码,沉迷学习,日渐消瘦。很荣幸能向大家分享我的所学,和大家一起进步,成为合格的卷王。如果文章有错误,欢迎在评论区指正。那么开始今天的学习吧!
那么今天的学习就到这里了。友友们觉得不错的可以给个关注,点赞或者收藏哦!感谢各位友友们的支持。以下的代码希望各位大佬们自行检验哦,毕竟亲手操作让记忆更加深刻。
我们今天继续学习JavaScript的基础语法结构
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
//定义一个空字符串,用来保存水仙花数
var str = "";
for (var i=100;i<1000;i++)
{
var a = i % 10; //提取个位数
var b = (i / 10) % 10 //提取十位数
b = parseInt(b); //舍弃小数部分
var c = i / 100; //提取百位数
c = parseInt(c); //舍弃小数部分
if (i == (a * a * a + b * b * b + c * c * c))
{
str = str + i + "、";
}
}
document.write("水仙花数有:" + str);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
var score=100;
if(score>60){
alert("那你很棒欧!");
}
if (score < 60) {
alert("补考!");
} else {
alert("通过!");
}
var result = (score < 60) ? "补考!" : "通过!";
alert(result);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
var day=3;
var week;
switch (day)
{
case 1:
week="星期一";break;
case 2:
week="星期二";break;
case 3:
week="星期三";break;
case 4:
week="星期四";break;
case 5:
week="星期五";break;
case 6:
week="星期六";break;
case 7:
week="星期日";break;
}
document.write("今天是"+week)
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
var n=1;
var sum=0;
while (n<=100)
{
sum+=n;
n=n+1;
}
document.write(sum)
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
var n = 1;
var sum = 0;
do
{
sum += n;
n++;
}while (n <= 100);
document.write("1+2+3+…+100 = " + sum);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
for(var i=0;i<5;i++ )
{
document.write(i+"
");
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
var n = 3.14;
if (parseInt(n.toString()) == parseFloat(n.toString()))
{
document.write(n+ "是整数")
}
else
{
document.write(n + "是小数")
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
//定义一个空字符串,用来保存水仙花数
var str = "";
for (var i=100;i<1000;i++)
{
var a = i % 10; //提取个位数
var b = (i / 10) % 10 //提取十位数
b = parseInt(b); //舍弃小数部分
var c = i / 100; //提取百位数
c = parseInt(c); //舍弃小数部分
if (i == (a * a * a + b * b * b + c * c * c))
{
str = str + i + "、";
}
}
document.write("水仙花数有:" + str);
</script>
</head>
<body>
</body>
</html>
那么今天的学习就到这里了。友友们觉得不错的可以给个关注,点赞或者收藏哦!感谢各位友友们的支持。以下的代码希望各位大佬们自行检验哦,毕竟亲手操作让记忆更加深刻。