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

Check to see if array is empty

Participant ,
Apr 24, 2009 Apr 24, 2009

Hi everyone,

I have a multiple choice quiz designed for a client. I have an array that works thruout the questions, that if the user answers incorrectly, it stores the question number in the array. When the user reaches the end of the quiz, I dont want this array to always display at the end, since the user could have all the asnwers correct (which means the array should be empty). I am trying to make an if else statement that will display a different message if the array is empty... but nothing I have tried works... any ideas? below is my code.

I tried this one:

if (questionsArray == null)
{
    questionsWrong.text ="All questions are correct!";
}else
{
    questionsWrong.text = "You missed question(s): " + questionsArray.toString();
}

and i also tried this one:

if ( questionsArray.toString == "")
{
    questionsWrong.text ="All questions are correct!";
}else
{
    questionsWrong.text = "You missed question(s): " + questionsArray.toString();
}

Thanks!

Rafa.

TOPICS
ActionScript
7.7K
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

Community Expert , Apr 24, 2009 Apr 24, 2009

check to see if your array's length is zero.

Translate
Community Expert ,
Apr 24, 2009 Apr 24, 2009

check to see if your array's length is zero.

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
Participant ,
Apr 24, 2009 Apr 24, 2009

That did the trick!

Thanks kglad!

code:

if ( questionsArray.length == 0)
{
    mytextField.text ="All questions are correct!";
}else
{
    mytextField.text = "You missed question(s): " + questionsArray.toString();
}

Rafa.

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 24, 2009 Apr 24, 2009
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