Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 密码检查器显示(0,0,0)的解锁,但不显示给定号码(密码)的解锁 import React,{useState}来自“React”; 导入“/App.css”; 函数App(){ 常量密码=[2,2,3]; const[digits,setDigits]=useState([0,0,0]); const[isUnlocked,setIsUnlocked]=useState(false); 设setDigitAtIndex=(数字,idx)=>{ 设置数字((当前数字)=> [ …currentDigits.slice(0,idx), 数字 …currentDigits.slice(idx+1) ] ); }; 让我们检查密码=()=>{ for(设i=0;i setDigitIndex(parseInt(event.target.value),1)}/> setDigitIndex(parseInt(event.target.value),2)}/> checkPassword()}>按我 {isUnlocked&&_Javascript_Html_Reactjs - Fatal编程技术网

Javascript 密码检查器显示(0,0,0)的解锁,但不显示给定号码(密码)的解锁 import React,{useState}来自“React”; 导入“/App.css”; 函数App(){ 常量密码=[2,2,3]; const[digits,setDigits]=useState([0,0,0]); const[isUnlocked,setIsUnlocked]=useState(false); 设setDigitAtIndex=(数字,idx)=>{ 设置数字((当前数字)=> [ …currentDigits.slice(0,idx), 数字 …currentDigits.slice(idx+1) ] ); }; 让我们检查密码=()=>{ for(设i=0;i setDigitIndex(parseInt(event.target.value),1)}/> setDigitIndex(parseInt(event.target.value),2)}/> checkPassword()}>按我 {isUnlocked&&

Javascript 密码检查器显示(0,0,0)的解锁,但不显示给定号码(密码)的解锁 import React,{useState}来自“React”; 导入“/App.css”; 函数App(){ 常量密码=[2,2,3]; const[digits,setDigits]=useState([0,0,0]); const[isUnlocked,setIsUnlocked]=useState(false); 设setDigitAtIndex=(数字,idx)=>{ 设置数字((当前数字)=> [ …currentDigits.slice(0,idx), 数字 …currentDigits.slice(idx+1) ] ); }; 让我们检查密码=()=>{ for(设i=0;i setDigitIndex(parseInt(event.target.value),1)}/> setDigitIndex(parseInt(event.target.value),2)}/> checkPassword()}>按我 {isUnlocked&&,javascript,html,reactjs,Javascript,Html,Reactjs,Unlocked} ); } 导出默认应用程序; 在react中运行此应用程序后,当我用0 0单击press me按钮时,它显示为unlocked,但在键入2 2 3后它不工作,但在键入223后它应该工作需要帮助?任何正在学习react的人都可以回答此问题 let setDigitAtIndex=(digit,idx)=>{ let temp = [...digits]; temp[idx] = digit; setDigits(temp); }; 这看起来

Unlocked

} ); } 导出默认应用程序; 在react中运行此应用程序后,当我用0 0单击press me按钮时,它显示为unlocked,但在键入2 2 3后它不工作,但在键入223后它应该工作需要帮助?任何正在学习react的人都可以回答此问题

let setDigitAtIndex=(digit,idx)=>{
    let temp = [...digits];
    temp[idx] = digit;
    setDigits(temp);
  };
这看起来容易多了

此外,您的checkpassword功能不正确

==
替换为
==

let checkPassword=() =>{
    for (let i=0;i<password.length;i++){
      if(password[i]!==digits[i]){
        setIsUnlocked(false);   // if the password is wrong, it will hide the text again
        return;
      }
    }
    setIsUnlocked(true);

  }
让checkPassword=()=>{

对于(设i=0;i
if(密码[i]==digits[i]){return;}
如果匹配,则退出..批准为答案