рони, поубирал лишнее
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
document.addEventListener("DOMContentLoaded", accordeon);
function accordeon() {
var accordBlocks = document.querySelectorAll('.accordBlocks'),
accordTitles = document.querySelectorAll('.accordTitles'),
index = null;
accordTitles.forEach((el,i)=>{
accordBlocks[i].style.display = 'none';
el.addEventListener('click', function(e){
el.style.color = '#fa05f6';
accordBlocks[i].style.display = 'block';
if(index != null){
accordBlocks[index].style.display = 'none';
accordTitles[index].style.color = 'black';
}
index = index==i? null: i;
});
});
}
</script>
<div class="accordTitles">1</div>
<div class="accordTitles">2</div>
<div class="accordTitles">3</div>
<div class="accordTitles">4</div>
<div class="accordTitles">5</div>
<div class="accordBlocks">1</div>
<div class="accordBlocks">2</div>
<div class="accordBlocks">3</div>
<div class="accordBlocks">4</div>
<div class="accordBlocks">5</div>
</body>
</html>