Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Begin Unverified Perl without End Unverified Issue

Can anyone see where the error is generating. When I go to upload Lighthouse is kicking back this message, but unlike the error log, this is pretty vague - that or I simply don't understand what it is trying to tell me.

" Error: Question 'Math' - HTML <head> Tag - Begin Unverified Perl without End Unverified."

[%Begin Unverified Perl 
 
 if (VALUE("Q1")==1)
  {
   SETVALUE("Q1Score",1); 
  }
   else
  {
   SETVALUE("Q1Score",0); 
  }
 
 if (VALUE("Q2")==4)
  {
   SETVALUE("Q2Score",1); 
  }
   else
  {
   SETVALUE("Q2Score",0); 
  }
 
 if (VALUE("Q3")==3)
  {
   SETVALUE("Q3Score",1); 
  }
   else
  {
   SETVALUE("Q3Score",0); 
  }
  
   if (VALUE("Q4")==4)
  {
   SETVALUE("Q4Score",1); 
  }
   else
  {
   SETVALUE("Q4Score",0); 
  }
  
   if (VALUE("Q5")==2)
  {
   SETVALUE("Q5Score",1); 
  }
   else
  {
   SETVALUE("Q5Score",0); 
  }
  
   if (VALUE("Q6")==4)
  {
   SETVALUE("Q6Score",1); 
  }
   else
  {
   SETVALUE("Q6Score",0); 
  }
  
   if (VALUE("Q7")==1)
  {
   SETVALUE("Q7Score",1); 
  }
   else
  {
   SETVALUE("Q7Score",0); 
  }
  
   if (VALUE("Q8")==4)
  {
   SETVALUE("Q8Score",1); 
  }
   else
  {
   SETVALUE("Q8Score",0); 
  }
  
   if (VALUE("Q9")==3)
  {
   SETVALUE("Q9Score",1); 
  }
   else
  {
   SETVALUE("Q9Score",0); 
  }
  
   if (VALUE("Q10")==2)
  {
   SETVALUE("Q10Score",1); 
  }  
   else
  {
   SETVALUE("Q10Score",0); 
  }
  
  if(GETVALUE([% PAGETIME(2) %]) <121)
    {
    SETVALUE("SpeedBonus",1.25);
    }
  if(GETVALUE([% PAGETIME(2) %]) >120 && GETVALUE([% PAGETIME(2) %])<181)
    {
    SETVALUE("SpeedBonus",1.10);
    }
  if(GETVALUE([% PAGETIME(2) %]) >180 && GETVALUE([% PAGETIME(2) %])<241)
    {
    SETVALUE("SpeedBonus",1.05);
    }
  if(GETVALUE([% PAGETIME(2) %]) >240)
    {
    SETVALUE("SpeedBonus",1.00);
    }

 
 SETVALUE("TotalCorrect",GETVALUE("Q1Score")+GETVALUE("Q2Score")+GETVALUE("Q3Score")+GETVALUE("Q4Score")+GETVALUE("Q5Score")+GETVALUE("Q6Score")+GETVALUE("Q7Score")+GETVALUE("Q8Score")+GETVALUE("Q9Score")+GETVALUE("Q10Score"));
 
  SETVALUE("TotalScore",(GETVALUE("TotalCorrect")*100));
  
  SETVALUE("TotalScoreWBonus",(GETVALUE("TotalCorrect")*(GETVALUE("SpeedBonus")*100)));
  
End Unverified%]
asked May 9 by RonH (195 points)

1 Answer

+3 votes
You should never have a "[% ... %]" inside of another "[% ... %]."  I've gone ahead and reworked lines 93 - 108:

if (PAGETIME(2) < 121) {
    SETVALUE('SpeedBonus', 1.25);
}
elsif (PAGETIME(2) < 181) {
    SETVALUE('SpeedBonus', 1.1);
}
elsif (PAGETIME(2) < 241) {
    SETVALUE('SpeedBonus', 1.05);
}
else {
    SETVALUE('SpeedBonus', 1);
}
answered May 9 by Zachary Platinum Sawtooth Software, Inc. (63,900 points)
And because you applied [if, elsif, elsif else], you were able to remove the full conditional script and shorten it. Nice work.
Thanks.  Using elses is a great way to shorten code and improve performance.  Another good coding practice in situations like this would be to call PAGETIME only once rather than three times:

my $pagetime2 = PAGETIME(2);
if ($pagetime2 < 121) {
    SETVALUE('SpeedBonus', 1.25);
}
elsif ($pagetime2 < 181) {
    SETVALUE('SpeedBonus', 1.1);
}
elsif ($pagetime2 < 241) {
    SETVALUE('SpeedBonus', 1.05);
}
else {
    SETVALUE('SpeedBonus', 1);
}


Probably not a significant speed change for code as short as this, but a good thing to keep in mind for larger scripts.
Yes, very true. Very neat and efficient programming. I'm sure speed is no issue here but good practice just the same.
Zachary,
 
Thank you. Needless to say I am a newb.  Good to know on the elsif. I had originally set the code up in a similar manner, but without the elsif - just if statements, thus it wasn't working correctly. Learning as I go here.

That all being said, it works great. Thanks for the quick reply!
...