1+1=11??? ActionScript3

Community Beginner ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

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?

Views

117

Likes

Translate

Translate

Report

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

Adobe Community Professional , Jan 19, 2021 Jan 19, 2021
Hi. Probably because your point variable is a string. Can you check this? Regards, JC

Likes

Translate

Translate
Adobe Community Professional , 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;

Likes

Translate

Translate
Adobe Community Professional ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

Hi.

 

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

 

Regards,

JC

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

change it to number, it show NaN

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

Did you initialized it like...

var point:int = 0;

 ...?

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

nope, just

var point:Number;

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

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;

 

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

ah lovely, it work.. thx mate..

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jan 19, 2021 Jan 19, 2021

Copy link to clipboard

Copied

LATEST

You're welcome!

Likes

Translate

Translate

Report

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