Comparison, nothing is true or all is true

line 21, I’m adding the condition for an if else branch, but it’s going from everything is true to nothing is true…
Feel like I’m missing something basic, but I’ve been staring at it for too long to see it. Asking for fresh eyes.

// JavaScript source code
var c = 0
var simon_sSequence = []
var player_sInput = []
const playerInput = document.getElementById('player_sInput')
const pads = document.querySelectorAll('.pad')

// Convert the pad list to an array so that 
// we can iterate over it using .forEach()
Array.from(pads).forEach((pad, index) => {

    // Get the associated audio element nested
    // in the pad-div
    const audio = pad.querySelector('audio')

    // Add a click listener to each pad which
    // will play the audio, push the index to 
    // the user input array, and update the span

    pad.addEventListener('click', () => {
        if (player_sInput[c] !== simon_sSequence[c]) {
           console.log("wrong");
        }//end of if
        else {
            audio.play()
            player_sInput.push(index)
            playerInput.textContent = "Player's reply " + player_sInput
            c++
            console.log(c);
        }//end of else
    })//end of EventListener
})//end of Array.from(pads).forEach((pad, index)

function audioBlack() {
    //generate a random number
    //push random number to simon_sSequence
    simon_sSequence.push(Math.floor(Math.random() * 3));
    console.log(simon_sSequence);
    $("#simon_sSequence").text("Simon says " + simon_sSequence);
    //  $("#player_sInput").text("Player's reply " +player_sInput);
    //for each in the array set time interval(300ms);
    //dipslay hover effect
    //play pad sound
    var audio = document.getElementById("audioBlue");
    audio.play();
    //clear player's input for this turn
    player_sInput = [];
    c = 0;
}

Starting to see it… my startTapper is also the fifth index in the array. I understand the issue now, still considering the best way to work around. what has to be the class pad, and what can be something else.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.