Skip to main content
Robb Nemo
Inspiring
June 15, 2023
Question

Update Dynamic text based on the score in Animate Multiple choice quiz

  • June 15, 2023
  • 2 replies
  • 996 views

Hi, I'm an animate novice, playing around with a html5 Multiple Choice quiz. It all works well, but I'd like to change the message displayed on the final score page dependent on the value of the total score achieved - so if  the total score is 0/3 a message something like "oops- total fail" appears. If the total score is 1/3 then a different message is displayed, and different messages again for each of 2/3 & 3/3. I'm sure it's a really simple thing to do, but any help would be greatly appreciated 

I have a dynamic textbox called "scorecomment" ready for the message, with the following code for the scoring:

var totalscore=3;
var thecoun=0;

this.totalscore.text=totalscore;
function scoreIt(){
thecount=thecount=1;
}

 

    This topic has been closed for replies.

    2 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    June 15, 2023

    Hi.

     

    You can use a switch statement or an if-else chain. Like this:

     

    Switch statement:

    var currentScore = 0; // set other values here
    
    switch(currentScore)
    {
    	case 0:
    		this.scorecomment.text = "You scored 0.";
    		break;
    	case 1:
    		this.scorecomment.text = "You scored 1.";
    		break;
    	case 2:
    		this.scorecomment.text = "You scored 2.";
    		break;
    	case 3:
    		this.scorecomment.text = "You scored 3.";
    		break;
    }

     

    Else-if chain:

    var currentScore = 0; // set other values here
    
    if (currentScore === 0)
    {
    	this.scorecomment.text = "You scored 0.";
    }
    else if (currentScore === 1)
    {
    	this.scorecomment.text = "You scored 1.";
    }
    else if (currentScore === 2)
    {
    	this.scorecomment.text = "You scored 2.";
    }
    else if (currentScore === 3)
    {
    	this.scorecomment.text = "You scored 3.";
    }

     

    I hope this helps.

     

    Regards,

    JC

    Robb Nemo
    Robb NemoAuthor
    Inspiring
    June 15, 2023

    Thank you JC for the response, it's very much appreciated

    Just a quick question though.... what do I write to set the other values? At the moment I only get "you scored 0" regardless of the score. 

    As I say, I'm very much the novice in these things! 🙂

    kglad
    Community Expert
    Community Expert
    June 15, 2023

    replace the quotes ("you scored x") with the text you want displayed

    Robb Nemo
    Robb NemoAuthor
    Inspiring
    June 15, 2023

    oops, I made a typo in the code and missed a "t" off ... it should be :

    var thecount=0;