Google Classroom
GeoGebraGeoGebra Classroom

Input Box for answering

adding two integers

Next applet shows an exercise in which the sum of two integers is asked. Conditional coloring of the Input Box gives feedback. Then try it yourself, following the given Construction Steps.

Try it yourself...

Construction Steps

1Type the command a = RandomBetween(1, 10) in the input bar and create the number a.
2Type the command b = RandomBetween(1, 10) in the input bar and create the number b.
3Type the command sol = a + b in the input bar and create the number sol.
4Type the command ans = 0 in the input bar and create the number ans.
5Toolbar ImageSelect the Text Tool and create the dynamic text a + b. Select a and b in the list of available objects to make the text dynamic.
6Toolbar ImageSelect the Input Box Tool and click in the Graphic to create an Input Box with Caption = and Linked Object ans = 0. Confirm with OK. Note: In the properties you can modify the length (in tab Style) and the Textstyle.
7Toolbar ImageSelect the Button Tool and click in the Graphic to create a button with label new exercise and GeoGebra Script UpdateConstruction().

Feedback with conditional colors

You can color the Input Box red when the answer is wrong and green when it's correct by using dynamic colors.
  • Rightclick on the Input Box.
  • Select Objects Properties to open the dialog.
  • Select the tab Avanced
Image
  • The syntax for Red: if ans is not equal to 0 neither to sol, the Input Box turns red. If not it doesn't.
  • The syntax for Green: if ans is equal to the solution it turns green. If not it doesn't. Note: By using 0.7 instead of 1 the green is slightly darker.
To prevent the Input Box from turning red when clicking on the button new exercise we have to add a supplementary command in the script of the button. Rightclick on the button and add in row 2 following command: SetValue(ans,0), which turns the number ans back to 0.
Image