Skip to main content
Participant
January 19, 2021
Answered

1+1=11??? ActionScript3

  • January 19, 2021
  • 1 reply
  • 571 views

i use this fucion

 

function ke_c2(event:MouseEvent):void
{
cek_a.visible=false;
cek_b.visible=false;
cek_c.visible=true;
cek_d.visible=false;
soal_selanjutnya.visible=true;
hasil = "Right Answer";
point +=1;
pointext.text = point.toString();
hasiltext.text = hasil;
a2.visible=false;
b2.visible=false;
c2.visible=false;
d2.visible=false;
}
 
so instead of 1+1=2 it show me 1+1=11. What i did wrong?
    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    nope, just

    var point:Number;

    That's the problem.

     

    You need to initialize a numeric variable before trying to do any mathematical operations on it.

     

    Just give it a value like 0.

    var point:Number = 0;

     

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 19, 2021

    Hi.

     

    Probably because your point variable is a string. Can you check this?

     

    Regards,

    JC

    Raa5CC4Author
    Participant
    January 19, 2021

    change it to number, it show NaN

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 19, 2021

    Did you initialized it like...

    var point:int = 0;

     ...?