I managed to make the code work using a for loop. However, I thought it could be more efficient to use the forEach method instead. How do I tweak my code so that it does what's expected to be doing? I'm might sound very basic, but I'm still a beginner.
const list = document.getElementsByTagName("li");
list.forEach(myFunction())
function myFunction(element, index) {
element[index].className = "newColor"
}
.newColor {
color: green;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Practise App</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<ul class="green" src="josue">
<li>Monday</li>
<li>Tuesday</li>
<li>Wednesday</li>
<li>Thursday</li>
<li>Friday</li>
<li>Saturday</li>
<li>Sunday</li>
</ul>
<script src="index.js" type="text/javascript"></script>
</body>
</html>