Ad

Function Executing Only The First Statement (if) And Not The Second One (else If)

- 1 answer

My code executes only the if statement (memefontsize) and forgets to execute the memefontsize2. If u need more information regarding my code let me know.

layer.add(scriptolutiondotcomtop2);
layer.draw();
var textscriptolutionheight2 = stage.getHeight();
layer.draw();


layer.add(scriptolutiondotcomtop);
layer.draw();
var textscriptolutionheight = stage.getHeight();
layer.draw();

function lowertopsize() {
  if (memefontsize > 10) {

    memefontsize = memefontsize - 1;
    memedotcomtop.fontSize(memefontsize);
    layer.draw()

  } else if (memefontsize2 > 10) {

    memefontsize2 = memefontsize2 - 1;
    memedotcomtop2.fontSize(memefontsize2);
    layer.draw();
  }
}
Ad

Answer

else or else if only execute when if condition is not satisfied.

If you wanna check both memefontsize and memefontsize2 you have to provide if instead of if..else

Try like this

if (memefontsize > 10) {

  memefontsize = memefontsize - 1;
  memedotcomtop.fontSize(memefontsize);
  layer.draw()

}
if (memefontsize2 > 10) {

  memefontsize2 = memefontsize2 - 1;
  memedotcomtop2.fontSize(memefontsize2);
  layer.draw();

}
Ad
source: stackoverflow.com
Ad