JsPsych-once button press (stimuli A), twice button press (stimuli B)

I want in JsPsych that when I press ‘w’ the stimulus as described will be presented. However when I press ‘w’ twice, another stimuli is displayed?

However, I tried it with a conditional function, but this did not seem to work. How can I fix this? (I am working with visual studio code)

ar w_press_count = 0; // Variable to keep track of 'w' key presses
var w_press_timeout;   // Variable to store the timeout ID

var explore_left = {
    type: 'html-keyboard-response',
    stimulus: function() {
        var square_left = `<div class="square_left">${Pract_Tasks[Random_index].logical}<br>${Pract_Tasks[Random_index].semantic}</div>`;
        return square_left;
    },
    choices: ['z', 'e', 'f', 'a', 'w'],
    on_finish: function(data) {
        if (jsPsych.pluginAPI.compareKeys(data.key_press, 'w')) {
            if (w_press_count === 0) {
                w_press_count++;
                w_press_timeout = jsPsych.pluginAPI.setTimeout(function() {
                    w_press_count = 0; 
                }, 1500);
            } else if (w_press_count === 1) {
                w_press_count++;
                jsPsych.pluginAPI.clearAllTimeouts(); 
                w_press_timeout = jsPsych.pluginAPI.setTimeout(function() {
                    w_press_count = 0; 
                }, 1500);
            }
        }
    }
};

var task_left = {  //first key press, this task.
    timeline: [explore_left],
    conditional_function: function() {
        var data = jsPsych.data.get().last(1).values()[0];
        return jsPsych.pluginAPI.compareKeys(data.key_press, 'w') && w_press_count === 1;
    }
};

var rules_left = {
    type: 'html-keyboard-response',
    stimulus: function(){
        square_left =  `<div class ="square_left">${Tasks[Random_index].lg}<br>${Tasks[Random_index].sm}</div>`;
    return square_left
    },
    choices: ['z','e','f','a'],
        }

var left_square = { // second key press this task.
    timeline: [rules_left], 
    conditional_function: function() {
        var data = jsPsych.data.get().last(1).values()[0];
        return jsPsych.pluginAPI.compareKeys(data.key_press, 'w') && w_press_count === 2;
    }
};

timeline.push(task_left);
timeline.push(left_square);