Jean LeLoup & Bob Ponterio
SUNY Cortland © 2009 |
Interactive Feedback from an Array
At times you may wish to provide must more detailed feedback to the student than simply saying if the response is right or wrong.
Here is one approach to this. We will store all of the feedback for all of the possible responses in an Array that one could think of as a Lookup Table. We can then use a very simple Javascript routine built-into our web page to look up the feedback and display it in a Textbox or Text Area. No matter how the student selects a response (buttons, hypertext link, etc.), the selection can activate the appropriate feedback.
Programming in JavaScript is beyond the scope of this course, but by copying a few small pieces of JavaScript code, we can add a significant interactive component to an activity. In this lesson, will will examine a very useful bit of JavaScript code that employs a common programming structure called a lookup table. A good example of this can be found in a Spanish lesson by Barbara Nelson at Colby College ( Spanish Grammar Exercises). Professor Nelson has graciously encouraged other teachers to use her code in their own lessons, so please be sure to acknoledge the source. http://www.colby.edu/~bknelson/SLC/ricitos1.php
Getting the JavaScript function into your page
To use this JavaScript function, we will get the basic code into our web page by pasting it into the <Head> portion of the page. The actual content of the feedback will need to be edited for any activity or when an activity is changed, so keeping the data in the web page instead of putting it in a separate file will make editing simpler.
<SCRIPT Language="JavaScript"> <!-- // var FBText = new Array(); //----------DATA STARTS-------- function Lookup(X,which) { |
This uses an Array called FBText to store the feedback. An Array is just a storage area that can hold many items. Each item can be refererence by a number. FBText[1] will hold the feedback for the firstresponse, FBText[2] will hold the feedback for another response, FBText[3], FBText[4], etc. Just follow the format in the Data Starts area above (equals sign, spaces, quotation marks and semi-colons) and create as many items as needed by copying, pasting, and changing the item numbers. Make sure that they are numbered sequentially.
The code also includes a Lookup function that shows the selected feedback text in a particular textbox.