Skip to main content
Participating Frequently
April 19, 2021
Answered

Show incorrect answer even answer it correctly

  • April 19, 2021
  • 2 replies
  • 722 views

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

This topic has been closed for replies.
Correct answer Colin Holgate

sorry. just change the permission

 


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

2 replies

JoãoCésar17023019
Community Expert
Community Expert
April 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

sayasaniAuthor
Participating Frequently
April 23, 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"

Colin Holgate
Inspiring
April 23, 2021

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

sayasaniAuthor
Participating Frequently
April 19, 2021

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