Show incorrect answer even answer it correctly

Community Beginner ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

hai, this is my code. everytime i answer correct answer which is "oksigen" it will show inccorect alert, but if i change from if(input1.text == "oksigen") to if(input1.text = "oksigen") then i will shpw the correct alert. why this happen? i already recheck all the instance name and everything just fine. Please help. Thank you.

 

stop();

import flash.events.MouseEvent

btnSemak01.addEventListener(MouseEvent.CLICK, bilaKlik);

function bilaKlik(event:MouseEvent): void
{
if(input1.text == "oksigen")
{
jawapanPelajar1.text = "congratulation, your answer is correct";
}
else
{
jawapanPelajar1.text = "sorry, please try again";
}
}

TOPICS
ActionScript, Error

Views

134

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 1 Correct Answer

Adobe Community Professional , Apr 22, 2021 Apr 22, 2021
Thank you for the very simple example file. I wonder if the right answer should be carbondioxide, and not oxygen, but that aside, your input field has a character it it already, and the user answer adds to the end of the text. Try this: stop(); import flash.events.MouseEvent btnCheck.addEventListener(MouseEvent.CLICK, onClik); input.text = ""; function onClik(event: MouseEvent): void { if (input.text == "oksigen") { answer.text = "Tahniah, jawapan anda betul"; } else { answer.text = "...

Likes

Translate

Translate
Community Beginner ,
Apr 18, 2021 Apr 18, 2021

Copy link to clipboard

Copied

forgot to tell. if i change from "==" to "=" i will get the error. and i know it because the correct whay is "==" not "="

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 ,
Apr 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

Hi.

 

Your code is correct. I run a test here and everything works just fine.

 

Do you have an FLA to share so we can investigate better?

 

Also, you should never use the assignment operator (=) in if statements. You should use the equality operator (==) or the strict equality operator (===) for cases like yours.

 

Here is a complete list of AS3 operators.

 

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

fla sample 

 

the correct answer should be oksigen but it show incorrect alert "Maaf, sila cuba lagi" instead of  correct alert Tahniah, jawapan anda betul"

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

You may need to set the permissions on that file so that anyone with the link can download it.

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

sorry. just change the permission

 

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Thank you for the very simple example file.

I wonder if the right answer should be carbondioxide, and not oxygen, but that aside, your input field has a character it it already, and the user answer adds to the end of the text. Try this:

 

stop();
import flash.events.MouseEvent

btnCheck.addEventListener(MouseEvent.CLICK, onClik);

input.text = "";

function onClik(event: MouseEvent): void {
	if (input.text == "oksigen") {
		answer.text = "Tahniah, jawapan anda betul";
	} else {
		answer.text = "Maaf, sila cuba lagi";
	}
}

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Thank you. btw, the questions is beside sugar what are the product of photosynthesis. so, the answer is oxygen. 

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

LATEST

Ah! It was the 'product' of photosynthesis. I was reading it as what was needed for photosynthesis. I wish I knew Malayan better.

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

stop();
import flash.events.MouseEvent

btnCheck.addEventListener(MouseEvent.CLICK, onClik);

function onClik(event:MouseEvent): void
{
if(input.text == "oksigen")
{
answer.text = "Tahniah, jawapan anda betul";

}
else
{
answer.text = "Maaf, sila cuba lagi";
}
}

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