Changing background color drop down menu via Jquery


I'm trying to change the background color of the navbar when someone clicks on the hamburger icon and the user has not yet scrolled down (since then the background color is already changed to white, also via Jquery script).

However, I'm running into an issue. For some reason I can change the background when a user clicks the button, but when they click again it does not change back.

The code I wrote:

var startY = $('.navbar').height() * 0; 

function checkScroll(){
    if($(window).scrollTop() > startY){

    if($(window).scrollTop() == startY){
        if($(".navbar-toggler").attr("aria-expanded", "false")){
            console.log("if werkt")
        else if($(".navbar-toggler").attr("aria-expanded", "true")){
            console.log("else werkt");

if($('.navbar').length > 0){
    $(window).on("scroll load resize", function(){

Can someone point me in the right direction here?

Thank you in advance!