Google Classroom
GeoGebraGeoGebra Classroom

empty Input Box for answering

Why an empty Input Box?

Firstly an Input Box with a value 0 doesn't look nice. Secondly one could think of exercises where 0 is the solution. In any case an empty Input Box is a better choice. To achieve this you can use use a trick: define ans=undefined. The result is that the inputbox for ans will be empty. But if you fill in a number, this number will show and applied to ans without any problem. In the button new exercise you can empty the inputbox again with the command SetValue(ans, undefined). See how this works in next applet and try it yourself following the Construction Steps.

Try it yourself...

Constrution Steps

1Type the command a = RandomBetween(1, 10) to create the integer a.
2Type the command b = RandomBetween(1, 10) to create the integer b.
3Type the command sol = a + b to create the integer sol.
4Type the command ans = undefined to create the integer ans.
5Toolbar ImageType the dynamic text a + b and select a and b in the list of available objects.
6Toolbar ImageSelect the Input Box Tool and create an Input Box with label = linked to the object ans.
7Toolbar ImageSelect the Button Tool and create a button with label next exercise and type as script the commands UpdateConstruction() and SetValue(ans, undefined) to empty the Input Box again.


Feedback with dynamic colors

To give feedback on the answer you can show texts as CORRECT or FALSE. But you might as well use dynamic colors to color the inputbox red if the given answer is false, green if the answer is correct and black if no answer is given yet. We only want the inputbox to color red if only an answer is already been given, in other words if ans is no longer undefined. This we can check with the condition ans == ans, since number is equal to itself unless it's undefined. Note that the double == signs will turn into the logic equal with question mark above it after tapping the Enter-tab.
Image