Web自学之JS循环小练习
前言
JS循环语句的两个小测试流氓表白法和流氓道歉法,代码编写纯属无聊哈!
如果有兴趣的朋友可以看看!😂😂😂
一、流氓表白法
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<script>
var num = 0;
do {
var input = prompt('你是不是喜欢我? 回答 是或不是');
if (input == '是') {
break;
}
else {
alert('回答错误! 请你认真回答这个问题!')
if ((num + 1) % 4 == 0) {
alert('不要欺骗自己!我想听听你内心的声音');
}
}
num++;
} while (input != '是')
alert('我就知道你会喜欢我的!');
alert('爱你,么么哒!');
</script>
<body>
</body>
</html>
二、流氓道歉法
代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>求求你原谅我吧</title>
</head>
<script>
var num = 0;
do {
var input = prompt('你是不是还在生我的气? \n回答:是或不是');
if (input == '不是') {
alert('真的吗?');
do {
var input2 = prompt('你是真的不生我气了吗? \n回答:真的或假的');
if (input2 != '真的') {
alert('你好坏呀!我就知道你会这么说的,我再给你一次机会!\n请你认真回答!');
}
else {
break;
}
} while (input2 != '真的')
// break;
}
else {
alert('回答错误! 请你认真回答这个问题!')
if ((num + 1) % 4 == 0) {
alert('不要欺骗自己!我想听听你内心的声音');
}
}
num++;
} while (input != '不是')
alert('我就知道你不会生我气的!');
alert('爱你,么么哒!');
</script>
<style>
body {
width: auto;
height: auto;
background-image: url('https://gss0.baidu.com/9vo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/728da9773912b31b717fbf4f8718367adab4e141.jpg');
background-repeat: no-repeat;
background-position: center top;
}
</style>
<body>
</body>
</html>