0

I'm trying to make an if else statement that should disable a button from being pressed when the value of c is 1, but I can't seem to get it to work with d3.js.

HTML

<button type="button" id="bt1" class="bt1">Previous 10</button>
<button type="button" id="bt2" class="bt2">Next 10</button>

JS

d3.select("#bt2").on("click", () => {
    a += 10;
    b += 10;
    c += 1;

    update(a,b,c);
});

d3.select("#bt1").on("click", () => {
    a -= 10;
    b -= 10;
    c -= 1;
    update(a,b,c);
});

if (c = 1) { d3.select("bt1").attr('disabled', 'disabled'); }
7rystan
  • 99
  • 2
  • 9

1 Answers1

1

You are only using one =. This results in the c variable having its value affected to 1, it does not test its value.

You can either use 2 or 3 =. See the difference here.

if (c === 1) { d3.select("bt1").attr('disabled', 'disabled'); }
Community
  • 1
  • 1
Erazihel
  • 7,295
  • 6
  • 30
  • 53