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

Show incorrect answer even answer it correctly

Community Beginner ,
Apr 18, 2021 Apr 18, 2021

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
632
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 1 Correct answer

LEGEND , 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 = "
...
Translate
Community Beginner ,
Apr 18, 2021 Apr 18, 2021

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

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

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

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

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"

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

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

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

sorry. just change the permission

 

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
LEGEND ,
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 = "Maaf, sila cuba lagi";
	}
}
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 ,
Apr 22, 2021 Apr 22, 2021

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

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

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

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

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";
}
}

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