Micro-Donations

If you are successfully making use of Mad Blanks for Joomla!, or if I have given you useful support, please donate $1 or more.

I pass on 10% of donations I receive through this site to the Joomla! project, so by supporting me, you're also supporting Joomla!


Thank you,
-Chris


The Starfish Story





Arithmetic tag tutorial PDF Print E-mail
Written by Chris Hallett   
Wednesday, November 11, 2009

The arithmetic tag looks like this:

[:arithmetic:{1st operand}:operator:{2nd operand}:]


You can use the following operators: + - * / %

  • + is for addition
  • - is for subtraction
  • * is for multiplication
  • / is for division
  • % is the modulo operator, which gives the remainder of a division operation (the modulus); one use for this is to tell if a number is evenly divisible by a certain number

Usage Example: [:arithmetic:{2}:+:{3}:] will show up in the Score Script output as 5.

The operands can include other Score Script tags.

Usage Example: [:arithmetic:{[:info:1:user_response:]}:*:{2}:] will multiply a number the website user entered for field #1 times two and display the output.

The arithmetic tag only supports two operands.

The workaround if you need to add or multiply more than two things together is to use expressions and then add or multiply the expressions together:

<expression:1>[:arithmetic:{2}:+:{3}:]</expression>
<expression:2>[:arithmetic:{3}:*:{5}:]</expression>

[:arithmetic:{[:expression:1:]}:+:{[:expression:2:]}:]

This will show up in the Score Script output as 20. Note again that you can also use other Score Script tags as operands.

If the user puts in four numbers for fields 1 through 4 you could do something like the following to add them all together:

<expression:1>[:arithmetic:{[:info:1:user_response:]}:+:{[:info:2:user_response:]}:]</expression>
<expression:2>[:arithmetic:{[:info:3:user_response:]}:+:{[:info:4:user_response:]}:]</expression>

[:arithmetic:{[:expression:1:]}:+:{[:expression:2:]}:]
 

 

Usage example: [:arithmetic:{[:info:5:user_response:]}:%:{2}:] will be 0 if a number the website user entered for field #5 is even (evenly divisible by two), or 1 if a number the website user entered for field #5 is odd (not evenly divisible by two).

See the linked survey to see an example of this.

Last Updated ( Wednesday, November 11, 2009 )
 
 
  Design by augs-burg.de & go-vista.de
This is the official website for Mad Blanks, a component written for Joomla!™
Mad Blanks, when used with Joomla!™, will allow you to give a quiz on your site. You can also use it to give a survey. Quizzes and surveys are popular applications on the Internet, including personality quizzes, name generators, and assessments.
This website and the featured software products herein written for Joomla!™ are the property of Chris Hallett, an independent programmer. Chris does not represent Open Source Matters, Inc. nor the Joomla!™ project.

www.madblanks.org | Mad Blanks - Quiz, survey, assessment, calculator, general purpose form | Privacy Policy | ©2010 Chris Hallett