the problem is the caret doesnt want to move to the next word after press the space keydown
here the code
this it for space function
function handleKeyDown() {
if (event.code === "Space") {
event.preventDefault();
if (game === "in progress") {
nextWord();
}
}
if (event.code === "Backspace") {
checkPrevLetter();
}
if (game === "waiting for input") {
startGame();
}
}
this is function for go to the next word
function nextWord() {
const isNotFirstLetter = letterIndex !== 0;
const isOneLetterWord = words[wordIndex].length === 1;
if (isNotFirstLetter || isOneLetterWord) {
wordIndex += 1;
letterIndex = 0;
increaseScore();
moveCaret();
}
}
this is the moveCaret function
function moveCaret() {
const offset = 4;
caretEl.style.top = `${letterEl.offsetTop + offset}px`;
caretEl.style.left = `${letterEl.offsetLeft + letterEl.offsetWidth}px`;
}
i have tried to adding a space between the word and removing the Space code and experiment all the code but none of them working correctly,
i want when user click space the caret should move to the first letter of the next word just like monkeytype.com if you familiar with it, thanks you so much
this is the repo for the full code :
https://github.com/firzalay/type-master