View Full Version : adding a function to test validity of another function

12-08-2006, 02:29 PM
i am creating a simon says game, the game is based on 4 images (each has an opposite) when the game begins one of the image randomly flashes, the flash is between itself and its opposite (day and night). the user is then to mimic that flash by clicking on that image. If he clicks in that image then i want the move to be correct or 'true' if he clicks on another image i want the move to be incorrect 'false'. if false he will be redirected to an alert box thats says game over, if true then 2 of the images then flash as opposed to only one, again randomly. I am unsure how to test if it is correct or incorrect and then if correct get 2 of the images to flash randomly and so on. Can anyone help? please? here is what i have so far :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Simon Says Game</title>

<style type="text/css">
body {
background-image : url('background.jpg');

table {
background-color: black;
margin-left: auto; margin-right: auto;
border-style: solid; border-color: black; border-width: 3px;

img {

#label {
width : 450px;
height : 82px;
position: absolute; top : 489px; left : 0 px;
font-family: arial; font-weight: bold; font-size: 25px;
text-align: center;

<script type="text/javascript">
function init(){
var image=document.getElementById('img'+randNumber);
var wen=image.id.charAt(3)+'day.jpg';

function f(obj,newImg){

oldImg = obj.src;



<body onload="init();">
<table border="5" width="900px" height="530px">
<tr width="900px" height="225px">
<td width="450px" height="225px"><img id=img1 src="1night.jpg" onclick="f(this,'1day.jpg')" title=this.src></td>
<td width="450px" height="225px"><img id=img2 src="2night.jpg" onclick="f(this,'2day.jpg')" title=this.src></td>

<tr width="900" height="225">
<td width="450px" height="225px"><img id=img3 src="3night.jpg" onclick="f(this,'3day.jpg')" title=this.src></td>
<td width="450px" height="225px"><img id=img4 src="4night.jpg" onclick="f(this,'4day.jpg')" title=this.src></td>
<tr width="900" height="80">
<div id="label">Retry</div>
<div id="label">Score: 0</div>