arpittyagi102 / speedykeys

Speedy Keys is a web-app made in react, to test and improve your typing speed🌟 Can you beat 50wpm ?? 🔥🔥🏎️🏎️
https://speedykeys.vercel.app
3 stars 3 forks source link

Fixed the bug #4

Closed KaustubhTrivedi closed 1 year ago

KaustubhTrivedi commented 1 year ago

There was a small mistake in your code.

in App.js You had written

function handleinputchange(e) {
    if (timetaken)
      return;
    if (starttime === 0) {
      start();
    }
    if (string === e.target.value) {
      setinputvalue("");
      console.log("Now we will change the i =", typeof (i));
      seti(prevIndex => prevIndex + 1);

      console.log("Changed value of i is ,", i);
      setstring(data[i].text);
      console.log("Now the changed string is ", string);
      return;
    }
    // if (e.target.value.length === 49)
    //   setinputvalue(inputvalue + " ")
    if (!string.startsWith(e.target.value)) {
      setwrong(true);
      setTimeout(() => setwrong(false), 500);
      setincorrect(incorrect + 1);
      return;
    }
    setinputvalue(e.target.value);
    setcorrect(correct + 1);
  }

In this function on this line

seti(prevIndex => prevIndex + 1);

You did not check if the prevIndex is a number or not. So when the code was getting executed on this line the prevIndex was getting set as String instead of a number.

So I solved it like

seti(prevIndex => parseInt(prevIndex) + 1);
vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
speedykeys ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 20, 2023 2:03pm