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

calculate score

New Here ,
Sep 05, 2007 Sep 05, 2007
Can someone pls help.
Script suppose to write correct and incorrect answers and then display in summary, but not working.
Below is main script and script for summary.
main script:
function QuizItem(question)
{
this.question=question;
this.answers=new Array();
//reset stats
this.numOfAnswers=0;
this.correctAnswer=0;

//returns question of this item
this.getQuestion=function()
{
return this.question;
}
// add answer to multiple choice items
this.addAnswer=function(answer, isCorrectAnswer)
{
this.answers[this.numOfAnswers]=answer;
if (isCorrectAnswer)
this.correctAnswer=this.numOfAnswers;
this.numOfAnswers++;
}
// this function returns the n-th answer
this.getAnswer=function(answerNumberToGet)
{
return this.answers[answerNumberToGet];
}
// returns index of corret answer
this.getCorrectAnswerNumber=function()
{
return this.correctAnswer;
}
// checks if the passed number is the correct answer index
this.checkAnswerNumber=function(userAnswerNumber)

{
if (userAnswerNumber==this.getCorrectAnswerNumber())
gotoAndPlay("Correct");
//Correct_Incorrect.text = "Correct";
else
gotoAndPlay("Incorrect");
//Correct_Incorrect.text = "Incorrect";
}


this.getNumOfAnswers=function()
{
return this.answers.length;
}
}

//this function parses the XML data into our data structure
function onQuizData(success)
{
var quizNode=this.firstChild;
var quizTitleNode=quizNode.firstChild;
title=quizTitleNode.firstChild.nodeValue;

var i=0;
// <items> follows <title>
var itemsNode=quizNode.childNodes[1];
// go thru every item and convert it into our data structure
while (itemsNode.childNodes )
{
var itemNode=itemsNode.childNodes
;
// <item> consists of <question> and one or more <answer>
// <question> always comes before <answer>s
// (Ie: <question> is the node 0 of <item>
var questionNode=itemNode.childNodes[0];
quizItems =new QuizItem(questionNode.firstChild.nodeValue);
var a=1;
//Go thru every answer and add to data structure
// <answer> follows <question>
var answerNode=itemNode.childNodes[a++];
while (answerNode)
{
var isCorrectAnswer=false;
if (answerNode.attributes.correct=="y")
isCorrectAnswer=true;
quizItems
.addAnswer(answerNode.firstChild.nodeValue, isCorrectAnswer);
// goto the next <answer>
answerNode=itemNode.childNodes[a++];
}
i++;
}
//decoding complete, start now
gotoAndStop("Start");
}

var quizItems=new Array();
var myData=new XML();
myData.ignoreWhite=true;
myData.onLoad=onQuizData;
myData.load("quiz.xml");
stop(); //continue when xml is loaded


summary script:
userScore=(numOfQuestionsAnsweredCorrectly*100)/(numOfQuestionsAnsweredIncorrectly+numOfQuestionsAnsweredCorrectly);

stop();

thanks,

alex
TOPICS
ActionScript
880
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 ,
Sep 05, 2007 Sep 05, 2007
use the attach code option to display code in this forum. and do some debugging to pinpoint the problem.
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
New Here ,
Sep 06, 2007 Sep 06, 2007
Code is above
boxes are dynamic and vars called out

Can you help.
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 ,
Sep 06, 2007 Sep 06, 2007
i can't help you if you can't read and understand english.

if english is not your first language use a translation service.
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
New Here ,
Sep 06, 2007 Sep 06, 2007
This is the code:

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 ,
Sep 06, 2007 Sep 06, 2007
have you made any attempt to pinpoint or, at least, narrow the problem? and what exactly is the problem?
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
New Here ,
Sep 06, 2007 Sep 06, 2007
Yes, I have . As I said at beginning correct answers and incorrect answers are suppose to be counted and then display in summary. you answer a question, it is either right or wrong. script is suppose to count both and put in summary of number right, number wrong and percent correct.


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 ,
Sep 06, 2007 Sep 06, 2007
is there a problem with the code you posted in your last message?
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
New Here ,
Sep 06, 2007 Sep 06, 2007
it wont' save any answers correct or incorrect to the total, all I get is 0 in total correct and 0 in total incorrect and NAN in percent which is in final summary.

I can't get it to work
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
New Here ,
May 15, 2009 May 15, 2009
LATEST

Hello iamalex,

Did you ever resolve this?

I have a very similar problem and would appreciate finding out what you learned.

Thanks in anticipation.

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