Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

1+1=11??? ActionScript3

Community Beginner ,
Jan 19, 2021 Jan 19, 2021

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?
494
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Jan 19, 2021 Jan 19, 2021

Hi.

 

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

 

Regards,

JC

Translate
Community Expert , Jan 19, 2021 Jan 19, 2021

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;

 

Translate
Community Expert ,
Jan 19, 2021 Jan 19, 2021

Hi.

 

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

 

Regards,

JC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 19, 2021 Jan 19, 2021

change it to number, it show NaN

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2021 Jan 19, 2021

Did you initialized it like...

var point:int = 0;

 ...?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 19, 2021 Jan 19, 2021

nope, just

var point:Number;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2021 Jan 19, 2021

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;

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 19, 2021 Jan 19, 2021

ah lovely, it work.. thx mate..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2021 Jan 19, 2021
LATEST

You're welcome!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines