2
I created an array with random values between 65 and 90 and turned it into an array of letters. So far so good. How do I find in this list (if it exists because it was created randomly) where the word DAD is formed when the loop is reading each index (letter) one by one.
let tabNombres = [];
let tabLettres = [];
let voyelles = 0;
let lettreE = 0;
//random numbers array
//Nombres aléatoires 65 à 90
for (let i = 0; i < 1000; i++) {
tabNombres.push(Math.floor(Math.random() * ((90 - 65) + 1) + 65));
}
// turning numbers into letters
// characters table
for (let j = 0; j <tabNombres.length; j++) {
tabLettres.push(String.fromCharCode(tabNombres[j]));
}
// triying to find D, A, D sequence
for (let i = 0; i<tabLettres.length ; i++){
for(let j=0; j<i; j++){
for(let k=0; k<j; k++){
if (tabLettres[k] === 'D' && tabLettres[j] === 'A' && tabLettres[i] === 'D'){
}
}
}
document.write(tabLettres.indexOf(i));
}
Welcome! Now read this how-to manual. https://pt.meta.Sstackoverflow.com/questions/1084/como-devemos-formatar-perguntas-e-respostas?cb=1
– André Martins
I believe the result is in the if:
if (tabLettres[k] === 'D' && tabLettres[j] === 'A' && tabLettres[i] === 'D'){
 //aqui certo, neste caso, vc tem que saber o índice de cada letra.
 }
– Ivan Ferrer