Skip to main content
fixed index error
Source Link
Quill
  • 11.9k
  • 5
  • 40
  • 93

Instead of having individual variables for each episode, and then iterating over all of them, use an array.

By using an array, you can use a for loop to iterate over all of them, turning the potentially massive amount of loops into one loop:

function season3episodesChange() {
    
    //Episodes:
    var episodes = [
        "1 - The Thin White Line",
        "2 - Brian Does Hollywood",
        "3 - Mr. Griffin Goes to Washington",
        "4 - One If by Clam, Two If by Sea",
        "5 - And the Wiener Is...",
        "6 - Death Lives",
        "7 - Lethal Weapons"
    ];
    
    var selectseason3episode = document.getElementById('selectseason3episode');
    
    for (var i = 1; i <= episodes.length; i++){
        if (selectseason3episode.value == episodes[i]episodes[i - 1]){
            document.getElementById('season3episode'+ i).style.display = 'inline-block';
        } else {
            document.getElementById(['season3episode' + i].join('')).style.display = 'none';
        }
    }
}

Instead of having individual variables for each episode, and then iterating over all of them, use an array.

By using an array, you can use a for loop to iterate over all of them, turning the potentially massive amount of loops into one loop:

function season3episodesChange() {
    
    //Episodes:
    var episodes = [
        "1 - The Thin White Line",
        "2 - Brian Does Hollywood",
        "3 - Mr. Griffin Goes to Washington",
        "4 - One If by Clam, Two If by Sea",
        "5 - And the Wiener Is...",
        "6 - Death Lives",
        "7 - Lethal Weapons"
    ];
    
    var selectseason3episode = document.getElementById('selectseason3episode');
    
    for (var i = 1; i <= episodes.length; i++){
        if (selectseason3episode.value == episodes[i]){
            document.getElementById('season3episode'+ i).style.display = 'inline-block';
        } else {
            document.getElementById(['season3episode' + i].join('')).style.display = 'none';
        }
    }
}

Instead of having individual variables for each episode, and then iterating over all of them, use an array.

By using an array, you can use a for loop to iterate over all of them, turning the potentially massive amount of loops into one loop:

function season3episodesChange() {
    
    //Episodes:
    var episodes = [
        "1 - The Thin White Line",
        "2 - Brian Does Hollywood",
        "3 - Mr. Griffin Goes to Washington",
        "4 - One If by Clam, Two If by Sea",
        "5 - And the Wiener Is...",
        "6 - Death Lives",
        "7 - Lethal Weapons"
    ];
    
    var selectseason3episode = document.getElementById('selectseason3episode');
    
    for (var i = 1; i <= episodes.length; i++){
        if (selectseason3episode.value == episodes[i - 1]){
            document.getElementById('season3episode'+ i).style.display = 'inline-block';
        } else {
            document.getElementById(['season3episode' + i].join('')).style.display = 'none';
        }
    }
}
hmm
Source Link
Quill
  • 11.9k
  • 5
  • 40
  • 93

Instead of having individual variables for each episode, and then iterating over all of them, use an array.

By using an array, you can use a for loop to iterate over all of them, turning the potentially massive amount of loops into one loop:

function season3episodesChange() {
    
    //Episodes:
    var episodes = [
        "1 - The Thin White Line",
        "2 - Brian Does Hollywood",
        "3 - Mr. Griffin Goes to Washington",
        "4 - One If by Clam, Two If by Sea",
        "5 - And the Wiener Is...",
        "6 - Death Lives",
        "7 - Lethal Weapons"
    ];
    
    var selectseason3episode = document.getElementById('selectseason3episode');
    
    for (var i = 1; i <= episodes.length; i++){
        if (selectseason3episode.value === episodes[i]){
            document.getElementById('season3episode'+ i).style.display = 'inline-block';
            break; // So you stop iterating over it once you've hit your target.
        } else {
            document.getElementById('season3episode'['season3episode' + ii].join('')).style.display = 'none';
        }
    }
}

Instead of having individual variables for each episode, and then iterating over all of them, use an array.

By using an array, you can use a for loop to iterate over all of them, turning the potentially massive amount of loops into one loop:

function season3episodesChange() {
    
    //Episodes:
    var episodes = [
        "1 - The Thin White Line",
        "2 - Brian Does Hollywood",
        "3 - Mr. Griffin Goes to Washington",
        "4 - One If by Clam, Two If by Sea",
        "5 - And the Wiener Is...",
        "6 - Death Lives",
        "7 - Lethal Weapons"
    ];
    
    var selectseason3episode = document.getElementById('selectseason3episode');
    
    for (var i = 1; i <= episodes.length; i++){
        if (selectseason3episode.value = episodes[i]){
            document.getElementById('season3episode'+ i).style.display = 'inline-block';
            break; // So you stop iterating over it once you've hit your target.
        } else {
            document.getElementById('season3episode' + i).style.display = 'none';
        }
    }
}

Instead of having individual variables for each episode, and then iterating over all of them, use an array.

By using an array, you can use a for loop to iterate over all of them, turning the potentially massive amount of loops into one loop:

function season3episodesChange() {
    
    //Episodes:
    var episodes = [
        "1 - The Thin White Line",
        "2 - Brian Does Hollywood",
        "3 - Mr. Griffin Goes to Washington",
        "4 - One If by Clam, Two If by Sea",
        "5 - And the Wiener Is...",
        "6 - Death Lives",
        "7 - Lethal Weapons"
    ];
    
    var selectseason3episode = document.getElementById('selectseason3episode');
    
    for (var i = 1; i <= episodes.length; i++){
        if (selectseason3episode.value == episodes[i]){
            document.getElementById('season3episode'+ i).style.display = 'inline-block';
        } else {
            document.getElementById(['season3episode' + i].join('')).style.display = 'none';
        }
    }
}
there, fix
Source Link
Quill
  • 11.9k
  • 5
  • 40
  • 93

Instead of having individual variables for each episode, and then iterating over all of them, use an array.

By using an array, you can use a for loop to iterate over all of them, turning the potentially massive amount of loops into one loop:

function season3episodesChange() {
    
    //Episodes:
    var episodes = [
        "1 - The Thin White Line",
        "2 - Brian Does Hollywood",
        "3 - Mr. Griffin Goes to Washington",
        "4 - One If by Clam, Two If by Sea",
        "5 - And the Wiener Is...",
        "6 - Death Lives",
        "7 - Lethal Weapons"
    ];
    
    var selectseason3episode = document.getElementById('selectseason3episode');
    var season3episode1 = document.getElementById('season3episode1');
    
    for (var i = 1; i <= episodes.length; i++){
        if (selectseason3episode.value = episodes[i]){
            season3episode1document.getElementById('season3episode'+ i).style.display = 'inline-block';
            break; // So you stop iterating over it once you've hit your target.
        } else {
            document.getElementById('season3episode' + i).style.display = 'none';
        }
    }
}

Instead of having individual variables for each episode, and then iterating over all of them, use an array.

By using an array, you can use a for loop to iterate over all of them, turning the potentially massive amount of loops into one loop:

function season3episodesChange() {
    
    //Episodes:
    var episodes = [
        "1 - The Thin White Line",
        "2 - Brian Does Hollywood",
        "3 - Mr. Griffin Goes to Washington",
        "4 - One If by Clam, Two If by Sea",
        "5 - And the Wiener Is...",
        "6 - Death Lives",
        "7 - Lethal Weapons"
    ];
    
    var selectseason3episode = document.getElementById('selectseason3episode');
    var season3episode1 = document.getElementById('season3episode1');
    
    for (var i = 1; i <= episodes.length; i++){
        if (selectseason3episode.value = episodes[i]){
            season3episode1.style.display = 'inline-block';
            break; // So you stop iterating over it once you've hit your target.
        } else {
            document.getElementById('season3episode' + i).style.display = 'none';
        }
    }
}

Instead of having individual variables for each episode, and then iterating over all of them, use an array.

By using an array, you can use a for loop to iterate over all of them, turning the potentially massive amount of loops into one loop:

function season3episodesChange() {
    
    //Episodes:
    var episodes = [
        "1 - The Thin White Line",
        "2 - Brian Does Hollywood",
        "3 - Mr. Griffin Goes to Washington",
        "4 - One If by Clam, Two If by Sea",
        "5 - And the Wiener Is...",
        "6 - Death Lives",
        "7 - Lethal Weapons"
    ];
    
    var selectseason3episode = document.getElementById('selectseason3episode');
    
    for (var i = 1; i <= episodes.length; i++){
        if (selectseason3episode.value = episodes[i]){
            document.getElementById('season3episode'+ i).style.display = 'inline-block';
            break; // So you stop iterating over it once you've hit your target.
        } else {
            document.getElementById('season3episode' + i).style.display = 'none';
        }
    }
}
Rollback to Revision 1
Source Link
Quill
  • 11.9k
  • 5
  • 40
  • 93
Loading
hmm
Source Link
Quill
  • 11.9k
  • 5
  • 40
  • 93
Loading
Source Link
Quill
  • 11.9k
  • 5
  • 40
  • 93
Loading