JavaScript中while语句练习
while语句练习题
完成⼀个验证密码的功能验证两次输⼊的密码是否⼀致。要求条件如下
运⾏代码如下:`
<meta charset="UTF-8">
while语句简单例子<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>学习JavaScript</title>
<script>
var pwd = prompt("请输⼊密码");
while ( pwd !=123456 ) {
pwd = prompt("请输⼊密码");
}
while (pwd == 123456) {
var pwdAgain = prompt("请再次输⼊密码");
if (pwdAgain == pwd) {
alert("两次密码⼀致");
break;
}
}
</script>
` 效果展⽰: ![第⼀次输⼊密码](img-blog.csdnimg/52226169aed546a285f6f80a050111e5.png?x-oss-
process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5peg5p6B6YCG5rWB,size_20,c olor_FFFFFF,t_70,g_se,x_16) ![密码为123456时](img-
blog.csdnimg/45e3f0c23243421481c1d8b4a5f17b76.png?x-oss-
process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5peg5p6B6YCG5rWB,size_20,c olor_FFFFFF,t_70,g_se,x_16) ![两次密码⼀样](img-blog.csdnimg/bd7d53d2a05f490898f7ec72fcbb7aba.png?x-oss-
process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5peg5p6B6YCG5rWB,size_20,c olor_FFFFFF,t_70,g_se,x_16) ![第⼀次密码错误⽆限循环](img-
blog.csdnimg/0b181c3607fd4f29b4894a9b993838f6.png?x-oss-
process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5peg5p6B6YCG5rWB,size_20,c olor_FFFFFF,t_70,g_se,x_16)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论