javascript - 如何使用 Javascript 制作密码提示,它将显示带有正确密码的图片或文本?
问题描述
如果输入了正确的密码,我希望显示图像或文本。我将如何制作一个“GUI”或命令行,上面写着:“输入密码”。如果你做对了,你可以看到隐藏的图像/文字吗?
解决方案
这是一个在 JS 中显示密码提示的小片段。
let randomPassword = "secretpassword";
let counter = 0;
let wasGuessed = false;
// give you three trys
while(!wasGuessed && counter < 3){
let pw = prompt("Type in a Password");
if(pw === randomPassword){
console.log("Here is the picture");
wasGuessed = true;
}else{
alert(`This was your ${counter+1} try`);
}
counter ++;
}
推荐阅读
- google-sheets - 无法在 div 中使用 importxml 和 xpath 导入文本
- r - 替换 Dataframe R 中的所有行
- python - 在python中不使用if语句根据用户输入执行部分代码
- typeorm - TypeORM 级联更新问题
- symfony - 使用 findBy 返回空数组集合
- python-3.x - 将数据框中的一列拆分为 6,列标题中的键和标题下的值
- java - java.net.BindException 运行 mvnw 失败:无法分配请求的地址
- flutter - 颤动圆形图像裁剪
- javascript - React 组件总是返回第一个代码
- javascript - 附加到日期选择器和 html.validationmessagefor 的日期字段未激活验证脚本