example_of_js_1.html 563 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>猜数字</title>
	</head>
	<body>
		<script>
			var answer = parseInt(Math.random() * 100 + 1)
			var counter = 0
			var yourInput
			do {
				counter += 1
				yourInput = prompt('请输入你猜的数字: ')
				if (yourInput > answer) {
					alert('小一点')
				} else if (yourInput < answer) {
					alert('大一点')
				} else {
					alert('恭喜你猜对了')
				}
			} while (answer != yourInput)
			if (counter > 7) {
				alert('智商余额不足')
			}
		</script>
	</body>
</html>