Thank you for getting back to me so quickly!
I refactored the code to wrap the repetitions in a function. However, for some reason, the problem persists. Here I’m attaching the full code. The problem lies between lines 210 and 324. This is a work in progress for a school project so don’t expect anything too fancy haha
<html>
<head>
<title>Final Assignment HV</title>
<style>
#theHeader {
font-family: arial;
color: pink;
font-size: 38px;
text-align: center;
}
.column {
float: left;
width: 25%;
}
h2 {
font-family: arial;
}
label {
font-family: arial;
}
a {
font-family: arial;
}
</style>
</head>
<body>
<h1 id="theHeader">Hendrick Valera Discography</h1>
<div class="column">
<h2 class="FilterHeader">Role</h2>
<input type="checkbox" id="check_1" value="1">
<label for="check_1">Producer</label> <br>
<input type="checkbox" id="check_2" value="2">
<label for="check_2">Mix Engineer</label> <br>
<input type="checkbox" id="check_3" value="3">
<label for="check_3">Mastering</label> <br>
<input type="checkbox" id="check_4" value="4">
<label for="check_4">Mix Assistant</label> <br>
<input type="checkbox" id="check_5" value="5">
<label for="check_5">Artist</label> <br>
<input type="checkbox" id="check_6" value="6">
<label for="check_6">Sax/Flute</label> <br>
<br>
</div>
<div class="column">
<h2 class="FilterHeader">Genre</h2>
<input type="checkbox" id="Gcheck_1" value="1">
<label for="Gcheck_1">Hip-Hop</label> <br>
<input type="checkbox" id="Gcheck_2" value="2">
<label for="Gcheck_2">R&B/Jazz</label> <br>
<input type="checkbox" id="Gcheck_3" value="3">
<label for="Gcheck_3">House</label> <br>
<input type="checkbox" id="Gcheck_4" value="4">
<label for="Gccheck_4">Reggaeton</label> <br>
<input type="checkbox" id="Gcheck_5" value="5">
<label for="Gcheck_5">Pop</label> <br>
<input type="checkbox" id="Gcheck_6" value="6">
<label for="Gcheck_6">Rock</label> <br>
<input type="checkbox" id="Gcheck_7" value="7">
<label for="Gcheck_7">Indie</label> <br>
<br>
</div>
<div class="column">
<h2 class="FilterHeader">Release Year</h2>
<select id="selectYear">
<option></option>
<option>2022</option>
<option>2021</option>
<option>2020</option>
<option>2019</option>
<option>2018</option>
<option>2017</option>
</select>
<br><br>
</div>
<div class="column">
<h2 class="FilterHeader">Search by Artist</h2>
<input type="text" id="ArtistSearch" value="Artist Name">
<br><br>
<button id="ClickSearch">Search</button>
<br><br><br><br><br><br>
</div>
<button>Reset Filters</button>
<br><br><hr><br>
<select id="sortBy">
<option value="defaultSelected">Sort By</option>
<option value="NewSelected">Date (Newest)</option>
<option value="OldSelected">Date (Oldest)</option>
<option value="AZSelected">Artist (A-Z)</option>
<option value="ZASelected">Artist (Z-A)</option>
</select>
<br><br><br>
<script>
let songs = [
/*
{
title: "",
artist: "",
role: "",
year: ,
genre: "",
stream: ""
},
*/
{
title: "What Are Friends For EP",
artist: "Chynna Lewis",
role: "Mix Assistant",
year: 2022,
genre: "R&B",
stream: "https://open.spotify.com/album/1PoY1vH332I6lOAyLZtZ20?si=toZMed-4Q2GazwwEFWW_7A"
},
{
title: "Stars",
artist: "Rishi Love",
role: "Mixing & Mastering",
year: 2022,
genre: "House",
stream: "https://open.spotify.com/track/5WGm3B206qsJzdwNztQVPM?si=cdd8dda610cc44be"
},
/*
{
title: "",
artist: "",
role: "",
year: ,
genre: "",
stream: ""
},
*/
{
title: "Airegin",
artist: "Braxton Cook",
role: "Mixing & Mastering",
year: 2021,
genre: "Jazz",
stream: "https://youtu.be/EX5WlDs0gNU"
},
/*
{
title: "",
artist: "",
role: "",
year: ,
genre: "",
stream: ""
},
*/
/*
{
title: "",
artist: "",
role: "",
year: ,
genre: "",
stream: ""
},
*/
/*
{
title: "",
artist: "",
role: "",
year: ,
genre: "",
stream: ""
},
*/
]
// Create full list of songs
function listSongs(arr) {
for (k in arr) {
div_song = document.createElement('div')
document.body.appendChild(div_song)
fullDisplay = document.createElement('a')
fullDisplay.className = "tuttiName"
fullDisplay.target = "_blank"
fullDisplay.innerHTML = arr[k].artist + " - " + arr[k].title + " (" + arr[k].role + ") " + " [" + arr[k].year + "]"
document.body.appendChild(fullDisplay)
fullDisplay.href = arr[k].stream
}
}
// default view of list
listSongs(songs)
// sorting section of the program
alphaArtist = document.getElementById("sortBy")
alphaArtist.addEventListener("change", (sortingBy) => {
for (k in songs) {
document.getElementsByClassName("tuttiName")[k].style.display = "none"
}
// Sort alphabetically by artist Name A-Z [default]
if (alphaArtist.value == "defaultSelected") {
for (k in songs) {
songs.sort(function ( a, b ) {
if (a.artist > b.artist ) {
return 1
}
if (a.artist < b.artist ) {
return -1
}
return 0
})
}
listSongs(songs)
}
// Sort alphabetically by artist Name A-Z
if (alphaArtist.value == "AZSelected") {
for (k in songs) {
songs.sort(function ( a, b ) {
if (a.artist > b.artist ) {
return 1
}
if (a.artist < b.artist ) {
return -1
}
return 0
})
}
listSongs(songs)
}
// Sort alphabetically by artist Name Z-A
if (alphaArtist.value == "ZASelected") {
for (k in songs) {
songs.sort(function ( a, b ) {
if (a.artist > b.artist ) {
return -1
}
if (a.artist < b.artist ) {
return 1
}
return 0
})
}
listSongs(songs)
}
// Sort by newest
if (alphaArtist.value == "NewSelected") {
for (k in songs) {
songs.sort(function ( a, b ) {
if (a.year > b.year ) {
return -1
}
if (a.year < b.year ) {
return 1
}
return 0
})
}
listSongs(songs)
}
// Sort by oldest
if (alphaArtist.value == "OldSelected") {
for (k in songs) {
songs.sort(function ( a, b ) {
if (a.year < b.year ) {
return -1
}
if (a.year > b.year ) {
return 1
}
return 0
})
}
listSongs(songs)
}
})
// Hide text in search bar
emptyArtist = document.getElementById("ArtistSearch")
function hideText() {
emptyArtist.value = ""
}
emptyArtist.addEventListener("click", hideText)
/*
*/
</script>
</body>
</html>
Thanks Paolo!