I am currently facing a challenge in attempting to store "p" tags into an array, and then using the ternary operator to determine if each "p" tag is even or odd.
- Is my approach correct for storing the "p" tags in an array?
- How can I utilize the ternary operator to iterate through the array and automatically designate even/odd (with different color backgrounds for better readability)?
This is the progress I have made so far. While I know how to manually define the evens and odds, I am struggling to apply the ternary operator to loop through the code and identify which "p" tags are even or odd.
function paragraph()
{
list = new Array();
var list = document.getElementsByTagName("p");
var even = list[0];
var odd = list[1];
even.style.backgroundColor = "#CCFFFF";
odd.style.backgroundColor = "#CCFFCC";
} //end of paragraph()
I find myself particularly challenged by working with arrays and loops. Any assistance on this matter would be highly valued and appreciated. Thank you in advance.