您的位置:首页 > Web前端 > JavaScript

JavaScript -- 猜数、遍历

2014-05-12 00:07 141 查看
----- 004-猜数.html -----

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>猜数</title>
</head>
<body>
<script type="text/javascript">
document.write("猜数游戏,0到100<br/>");
theNo = Math.round(Math.random()*100);
x = window.prompt("请输入要猜的数字:");
count = 1;
while(x != theNo)
{
document.write("猜了"+count+"次了<br>")
count ++;
if(x < theNo)
x = window.prompt("太小,请重猜:");
else
x = window.prompt("太大,请重猜:");
}
document.write("你猜了"+count+"次,终于")
document.write("猜对了!是"+theNo);
</script>
</body>
</html>




----- 005-遍历.html -----

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Titanic</title>
</head>
<body>
<script type="text/javascript">
var ti = new Object();
ti.name = "泰坦尼克号";
ti.weight = "46328吨";
ti.sunkTime = "1912年4月14日晚11点40分";
for(prop in ti)
{
document.write("属性:"+prop+"<br/>");
document.write("值:"+ti[prop]+"<br/><br/>")
}
</script>
</body>
</html>


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: