首页 > 解决方案 > 如何使用 Javascript 制作密码提示,它将显示带有正确密码的图片或文本?

问题描述

如果输入了正确的密码,我希望显示图像或文本。我将如何制作一个“GUI”或命令行,上面写着:“输入密码”。如果你做对了,你可以看到隐藏的图像/文字吗?

标签: javascriptpasswords

解决方案


这是一个在 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 ++;
}


推荐阅读