-1

i want to make if condition. in that condition, if the condition is score = multiple of two. how to make the code?

if(score >= 2){         
            //removeChild(Batumc);
            //removeChild(Batumc1);

            //model soal
            Soal_mc.angka1.text = mtk1.toString();
            Soal_mc.op.text = "+";
            Soal_mc.angka2.text = mtk2.toString();

            //soal muncul
            TweenLite.to(Soal_mc, 1, {x:350 ,y:180, alpha:1, ease:Expo.easeOut});
            }

but i want this code

if(score >= 2)

become to

if(score multiple of 2){}
Tamara
  • 23
  • 7
  • 2
    if((score % 2) == 0) {} (Look up "modulo operator" for an explanation, or I can write a more detailed answer if you like) – Not so Veteran Sep 19 '19 at 08:32
  • sure, if you approve. please explain in simple explanation :) – Tamara Sep 19 '19 at 08:48
  • 2
    Modulo is simply a division operation but instead of returning the quotient it returns the remainder. Since an even number divided by 2 has no remainder, you can ensure a number is a multiple of two if you use `score % 2 == 0`, as any even number will return 0 and any odd will return 1. – ugotopia123 Sep 19 '19 at 20:22
  • thank's @ugotopia123 – Tamara Sep 20 '19 at 06:53

1 Answers1

0

Try this:

if(score >=2) {
    if((score % 2) == 0) {
        //your code goes here
    }
}

The score % 2 returns the remainder of the division, and if this return is equals to 0, it means is multiple.

ofernandoavila
  • 124
  • 1
  • 8
  • I think so, but if i don't use ````if(score >= 2)````, can i? it is effective just to use ````if((score % 2) == 0)````, isn't it? – Tamara Sep 26 '19 at 06:59
  • Yes! I just add this condition because I thought that you want to have a score superior ou equals to 2 – ofernandoavila Mar 03 '20 at 00:06