witam wszystkich, naprawde zaciąłem się przy zadaniu sprawdzającym czy dany string zawiera tylko łacińskie litery i czy nie ma dwóch dużych/małych liter tuż obok siebie. zalozylem taki plan:
1.sprawdź czy string zawiera tylko łacińskie znaki.
2. sprawdz czy sa duze litery
3. umieść .indexof dużych liter do tablicy
4. użyj .map do tablicy aby znaleźć różnice indexof, czyli gdy różnica wyniesie 1, to znaczy ze dwie duże litery są obok siebie.
5. sprawdź to samo dla malych liter
A wiec, gdy próbuje wrzucić pozycje liter do tablicy (punkt 3),console.log zwraca mi pusta tablice. Próbowałem tu .concat, .push, pętle - i nic nie działa.
bez tego nie mogę przejść dalej.
Proszę o jakieś porady.
const task101 = () => {
const task101in = document.querySelector("#task101in").value;
const t101ans = document.querySelector("#task101ans");
const another = [];
//if length of string is not the same as length of latin letters
if ((task101in.match(/[a-zA-Z]/g) || "").length != task101in.length) {
t101ans.textContent = `Non Latin letters, try again`;
} else {
//looking for uppercase letters
for (let i = 0; i < task101in.length; i++) {
//check index of uppercase
const indexNum = task101in.indexOf(task101in[i].match(/[A-Z]/g));
//trying to push indexof numbers to an array
for (let y = 0; y <= indexNum.length; y++) {
// const another = [];
another = another.push(indexNum)
return another
}
t101ans.textContent += indexNum
}
}
};
document.querySelector("#task101").addEventListener("click", task101);