| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

repeatable randomized questions

Page history last edited by Mike May, S.J. 13 years, 8 months ago

Creating a refreshable quiz with random values

 

We want to create an applet that can be used for drill and practice.  To do this we need something that will generate a question with random values and then let the student know if they have gotten the question correct.  We would also like to have an easy way for the student to have the applet try the problem again with a new set of values.

 

Setting up a random problem

 

We choose as our base activity having the student drag a point to a set of Cartesian coordinates.  We want the worksheet set up with the grid showing and the same scale factor used for the x and y axes.

 

Next we would like to create a point at a randomly chosen grid point, and a point that we will have to drag to that point. 

 

A=(-5,3)

A' = (RandomBetween[ceil(x(Corner[1])), floor(x(Corner[3]))], RandomBetween[ceil(y(Corner[1])), floor(y(Corner[3]))])

 

These commands take a bit of explanation.  The first command creates a point named A at the coordinates (-5,3).  The second command creates a point named A'.  Corner[1] is a hidden point at the lower left corner of the screen.  Corner[3] is a hidden point at the upper right corner of the screen.  The RandomBetween command chooses a random integer between two integer.  The ceil and floor commands are used to round up from the bottom and round down from the top.  Thus we get a point A' at a random lattice point on the screen.

 

 

Now we need to add text with the instructions to the student.

 

Once again, some explanation is in order.  The text between the double quotes is followed by the value of the point A.  These objects are connected with a plus sign.

We also want to add a message to let the student know they have completed the task.  (Currently, the second line of the instructions is a bit confusing.  We don't have that box yet.)

 

 

We would also like to have something that lets us know if the dragged point has been dragged to match the chosen point.  This variable is a Boolean variable with values of true and false.

 

We create the variable with the command:

Agood = Distance[A, A'] < 0.1

 

Since GeoGebra internally tracks numbers to 15 digits, instead of asking if the points are equal, we ask if they are close enough.  We find within 0.1 is close enough to be considered equal for this kind of test.

 

 

Agood  will not show up in the algebra window.  When we look at the object properties, it is visible.  We want to make text2, the congratulatory comment, visible when Agood is true.

 

 

Allowing a new problem

 

We now want to let the user ask for a new problem.  We will do this with a Check Box.  We label the check box "Give a New Problem", and do not connect it to any object.

 

In the properties window, I rename the check box as Reset.

 

 

Reset is actually a Boolean value that is true when the check box is checked and false when it is not checked. 

We now change the definition of A' a little bit.  We add  "+Reset*(0,0)" to the end of the definition of A'.  This means that every time the value of Reset is changed, the value of A' is recomputed.  This lets the user ask for a new problem, which is again randomly chosen.

 

 

Adding a timer to a page

 

It is relatively easy to add a timer to a page like this.  We add some JavaScript to the page to do this.  This is easiest to understand if we break the JavaScript into conceptual blocks.  All of the JavaScript goes immediately after the end of applet tag. (</applet>)

 

The first block produces a button with a label "Start/Stop timer" and a yellow strip where messages are displayed.

 

<form

//Block 1 - The button to start and stop the timer and the timer message bar>

<input value="Start/Stop timer" onclick="clickHandler()">

 </form  \\ This provides the button to start/stop the timer.>    

 

<div id="timerText" style="border: medium solid ; background:
rgb(255, 255, 204) none repeat scroll 0% 0%; height: 1.3em;
font-size: 1.5em; color: red; -moz-background-clip:
border; -moz-background-origin:
padding; -moz-background-inline-policy: continuous;"></div>

 

After we have added the form to the page, we add the scripts that tell the page what to do.   First we set up some variables

 

<script>

//The JavaScript itself

//Block 2 - setting up background variables

 

var elapsed_time = 0; 

var best_time = -1;

var ival;           // ival is an "interval object"

var timerRunning = false; 

var applet = document.ggbApplet;

 

In the next block of code we produce functions for printing messages in the message bar.

 

function timeDisplay(msg) {

      var elapsed_string;

      var best_string;

      elapsed_string = timeToText(elapsed_time) + "         ";

      if (best_time < 0) {   //initially, best_time = -1

            best_string = "";

      }

      else {

            best_string = "Best: " + timeToText(best_time) + "       ";

      }

      document.getElementById("timerText").innerHTML = elapsed_string + best_string + msg;

}

 

function timeToText(t) {

      var tstr = t.toString();

      if (t < 0) { return ""; }

      if (t > 1000) { return tstr.slice(0,4); }

      if (t > 100) { return tstr.slice(0,3); }

      if (t > 10) { return tstr.slice(0,4); }

      if (t > 0) { return tstr.slice(0,3); }

      //remaining case: t == 0.

      return "0.0" ;

}

 

The last block of code is the function executed when we click on the button.  For this applet, the student has correctly followed instructions when the Boolean variable Agood is true.  When JavaScript gets the value of a Boolean variable from GeoGebra, true becomes 1 and false becomes 0.  This is the block that will get modified with different applets.  In particular, the test for following instructions may shift, and the message for having followed the instructions correctly or not may change.

 

function clickHandler() {

// If the timer is off, start it.

//wait 0.8 seconds, then start to execute running() every 0.1 seconds

//waiting allows the applet to reset

      if (timerRunning == false) {

            timerRunning = true;

            elapsed_time = 0;

            setTimeout("ival = setInterval('running()', 100)", 800);     

      }

// If the timer is on, stop it, and print one of three messages

// See if the student completed the task correctly

// If so, and if we have a new best time print the best time message

// If so, and the time is not best, print a simpler message.

// If not, tell the student the point is in the wrong place.

      else {

            timerRunning = false;

            clearInterval(ival);

            if (applet.getValue("Agood") == 1) {

                  if (elapsed_time < best_time || best_time == -1) {

                        best_time = elapsed_time;

                        timeDisplay("New best time!");      }

                  else { timeDisplay("Good!"); }

            }

            else { timeDisplay("The point is not placed properly :-("); }

            setTimeout("timeDisplay('')", 3000);

      }

}

 

function running() {

      timeDisplay("");

      elapsed_time = elapsed_time + 0.1;

}

 

 

</script>

 

This gives the modified web page with the timer.

 

 

This tutorial explains a technique that was first shown to me by Marc Renault at Shippensburg University

 

 

The applet with timer can be found at < http://www.slu.edu/classes/maymk/GeoGebra/RandomQuizTimerNoGGB.html>.

© 2010 Mike May, S.J.

 

This tutorial explains a technique that was first shown to me by Marc Renault at Shippensburg University

 

The applet can also be checked.

Link to applet

© 2010 Mike May, S.J.

 

Comments (0)

You don't have permission to comment on this page.