<!--------------------------------------------- File function.html Illustrates a function in JavaScript -----------------------------------------------> <html> <head> <title>Functions in JavaScript</title> <script language="JavaScript"> <!-- hide from older browsers //Define function testQuestion() function testQuestion(question) { //Define local variables for the function var answer=eval(question); var output="What is " + question + "?"; var correct='<img src="ok.gif">'; var incorrect='<img src="wrong.gif">'; //Ask the question var response=prompt(output, ""); //Check the result return (response == answer) ? correct : incorrect; } // stop hiding --> </script> </head> <body bgcolor="#FFFFFF"> <p> <h2>using the <tt>eval</tt>() function to test input</h2> <script language="JavaScript"> <!-- hide from older browsers //Ask question and output the result var result=testQuestion("10 + 10"); document.write(result); // stop hiding --> </script> <p> <hr> </body> </html>