- Joined
- Sep 12, 2022
- Messages
- 39
- Reaction score
- 0
I have tried many methods, the latest gives no output. Here are my codes. At other attempts, I got the array to display but not as wanted. Examples of how it's to display are these(I capitalized the strings which are from the array):
NOTE, each is a separate div which has been looped to give them similar attributes like class, The array output with the strings is added as the text content of each of the divs
My best output
The FIRST SECOND THIRD question
The FIRST SECOND THIRD question
The FIRST SECOND THIRD question
Expected Output
The FIRST question
The SECOND question
The THIRD question
NOTE, each is a separate div which has been looped to give them similar attributes like class, The array output with the strings is added as the text content of each of the divs
My best output
The FIRST SECOND THIRD question
The FIRST SECOND THIRD question
The FIRST SECOND THIRD question
Expected Output
The FIRST question
The SECOND question
The THIRD question
HTML:
<body>
<main>
<section>
<div>
</div>
<div>
</div>
</section>
<section>
<div>
</div>
<div>
</div>
</section>
<section>
<div>
</div>
<div>
</div>
</section>
</main>
JavaScript:
const myArr = ['first', 'second', 'third'];
for (let o = 0; o < myArr.length; o++){
console.log(`The ${myArr[o]} question`)
const divOne = document.querySelectorAll('.eachSection-class div:nth-of-type(1)');
for (j = 0; j < divOne.length; j++) {
divOne[j].classList.add('divOne-class');
divOne[j].textContent = `The ${myArr[o]} question`;
}
console.log(divOne);
}