Tutorial 5 - Randomization, Input, and Feedback

In this tutorial, we use random numbers to graph a random linear function (random slope and random y intercept), receive input from the user, and give feedback if the answer is correct or not.  The expected output of this tutorial is shown below. [br]
Expected output
1.) Graphing a random linear function
[br]To generate a random slope and a random y-intercept, type the following in the Input bar: [br][br][color=#0000ff]a = randombetween(-5,5)[br]b = randombetween(-5,5)[/color][br][br]To draw plot the graph, type the following in the Input bar. [br][br][color=#0000ff]f(x) = ax + b[br][br][/color]The [i]randombetween(a,b)[/i] command generates random integers between a and b where a < b.
2. Generating new random linear functions
Now that we have a linear function graph, we need a button to create new random lines. [br][list=1][*]To create this button, select the Button tool from the Toolbar, and then click on the Graphics view. [/*][*]In the Button dialog box, type [color=#0000ff]New Line[/color] in the Caption text box, type [color=#0000ff]UpdateConstruction()[/color] in the [i]GeoGebra Script[/i] textbox, and then click on the [b]OK[/b] button.[/*][/list]
The UpdateConstruction() command refreshes all the objects in GeoGebra and therefore generates new random numbers. You can generate new random lines by clicking on the [b]New Line [/b]button.
3.) Receiving input from the user
We now let the users guess the equation of the linear function graph. They will use the Input box to type their equation. To construct the Input box, do the following[br] [list=1][*]In the Input bar, type [color=#0000ff]g(x) = ?[/color].[color=#0000ff] [/color]Here[color=#333333],[/color] g is undefined and will store the equation from by the user. [/*][*]From the Toolbar, select the [i]Input box[/i] tool and then click on the[i] Graphics view[/i]. [/*][*]In the dialog box, type [color=#0000ff]Type your answer here:[/color] in the Caption box, select[i] g(x) = ?[/i] in the [i]Link Object[/i] box, and then click the [b]OK[/b] button. You can move the Input box by selecting the Move tool and then dragging it while holding the right mouse button. [/*][*]Type the equation of a linear function in the Input box. Notice that this will replace the ? symbol as the equation for the function g. [/*][*]Every time we click on the [b]New Line[/b] button, we need to set the value of the function g to undefined, so we add the code [color=#0000ff]g(x) = ?[/color] below the UpdateConstruction() script[color=#ff0000] [/color]in the [b]New Line[/b] button. You can edit the script by right clicking on the [b]New Line [/b]button, selecting [i]Settings[/i] and then clicking on the [i]Scripting[/i] tab in the Settings panel.[/*][/list]
4.) Comparing the function with user's answer
To compare the user's answer [i]g[/i] to the given function [i]f[/i], type the following in the Input bar. [br][br][center][color=#0000ff]iscorrect = f == g  [/color][/center]This command returns “true” if the user's answer equals the given function, otherwise false,  and then assign the value to[i] iscorrect[/i]. Note that iscorrect is a variable, you can replace it with other letters or words. [br]
5.) Giving Feedback
We will write two feedback texts for students. The feedback for the correct answer will appear if the variable “iscorrect” is true, otherwise the incorrect answer feedback will appear. Below are the text that will appear if the students' answer if correct and incorrect. [br][br]Text1: You are correct! Good job![br]Text2: That is incorrect. Please try again.[br][br]To create the feedback text, do the following:[br][br][list=1][*]Create two texts using the Text tool and type the two feedbacks above, one for each textbox. [/*][*]Right click on Text1, select [i]Settings[/i], and then select the [i]Advanced[/i] tab in the Settings panel. In the [i]Condition to Show Object[/i] text box, type[color=#0000ff] iscorrect == true[/color]. This means that it will show Text1 if the answer is correct.  [/*][*]Use the same steps for Text2 but set the [i]Condition to Show Object[/i] as [color=#0000ff]iscorrect == false[/color].[/*][*]Note that Text2 will also appear when the [b]New Line[/b] button is clicked (Why?). To solve this problem, type [color=#0000ff]isgdefined = Isdefined(g) [/color]in the Input bar. This command returns true of g is defined, otherwise, returns false. [/*][*]Edit the [i]Condition to Show Object[/i] of Text2 to [color=#0000ff]iscorrect == false ^ isgdefined == true[/color]. This means that Text2 will only show if the user has typed the answer and the answer is incorrect. [/*][/list]
Watch the tutorial video

Information: Tutorial 5 - Randomization, Input, and Feedback