Goals :
- To require the user to input the displayed words in the designated fields.
- To validate if the typed words are an exact match to those requested.
- If correct, proceed to the next word.
- If incorrect, prompt the user to retype the wrongly entered word.
All the words are stored in an array.
Achievements so far :
Goals 1 to 3 have been successfully met!
Challenges faced :
Goal 4 is partially achieved. The issue lies in restarting the entire loop instead of keeping track of progress and resuming from the incorrectly answered question.
The code snippet :
wordList = ["Cachalot", "Pétunia", "Serviette"]
score = 0
for (let i=0; i<wordList.length; i++){
let typedWord = prompt("Please type the following word: " + wordList[i])
if(typedWord===wordList[i]){
score+=1
console.log(score)
} else{
console.log ("Please try again.")
typeSmart()
}
}
}typeSmart()
I understand that calling the function restarts the whole process. However, I am unsure how to proceed differently. Should I utilize a while loop instead or in conjunction with the current for loop?