This is a code I wrote about a javascript game which you should click on each picture so it will move and then the puzzle will be done. I have nine pictures with each picture named 1.jpg 2.jpg — 9.jpg
I have three difficulties beginner intermediate hard . The code has logical errors I can’t understand . can anybody help me
[code]
<html>
<head>
<title> CAIS326 Assignment 3 </title>
<script type=”text/javascript”>
<!–
var seconds = 0;
var timerId;
var time;
var Click1 = 0,Click2 = 0,Click3 = 0,Click4 = 0,Click5 = 0,Click6 = 0,Click7 = 0,Click8 = 0,Click9 = 0;
var Pictures = [1,2,3,4,5,6,7,8,9];
function SwapImages()
{
for(var q=0 ; q<9; q++)
document.getElementById(“image+q+”).src = Pictures[Click+q+ -1]+”.jpg”;
}
function RegisterClicks(Index)
{
if (Click1 == 0)
Click1 = Index;
else if (Click2 == 0)
Click2 = Index;
else if (Click3 == 0)
Click3 = Index;
else if (Click4 == 0)
Click4 = Index;
else if (Click5 == 0)
Click5 = Index;
else if (Click6 == 0)
Click6 = Index;
else if (Click7 == 0)
Click7 = Index;
else if (Click8 == 0)
Click8 = Index;
else if (Click9 == 0)
Click9 = Index;
for(var m=0; m<9; m++)
{
if (Click+m+ > 0 && Click+m + 1+ > 0){
SwapImages();
Click+m+ = 0;
Click+m + 1+ = 0;
}
}
}
function startTimer() {
if (document.form1.gamelevel[0].checked)
time=60;
else if (document.form1.gamelevel[1].checked)
time=45;
else
time=30;
// 1000 milliseconds = 1 second
timerId = window.setInterval( “updateTime()”, 1000 );
}
function updateTime() {
seconds++;
soFar.innerText = seconds;
if ( time == seconds)
{
seconds = 0;
window.alert (“Game over Loser…”);
clearTimeout(timerId);
}
}
var array = new Array(9);
for (var i=0; i<9; i++)
{
array[i] = i+1;
}
shuffle();
document.writeln(“<table border=1>”);
var b = 0;
while (b < 9 )
{
var num = array[b];
document.writeln(“<tr><td><img src=””+num+”.jpg” id =”image”+num+” ” onClick=”RegisterClicks(“+num+”)” /></td>”);
++b;
num = array[b];
document.writeln(“<td><img src=””+num+”.jpg” id =”image”+num+” ” onClick=”RegisterClicks(“+num+”)” /></td>”);
++b;
num = array[b];
document.writeln(“<td><img src=””+num+”.jpg” id =”image”+num+” ” onClick=”RegisterClicks(“+num+”)” /></td></tr>”);
++b;
}
document.writeln(“</table>”);
function shuffle()
{
var k = 9;
var RandNum;
var Temp;
for (var n=0; n<9; n++)
{
RandNum = Math.floor(Math.random()*k);
Temp = array[k-1];
array[k-1] = array[RandNum];
array[RandNum] = Temp;
k=k-1;
}
}
//–>
</script>
</head>
<body>
<form name = “form1” action = “”>
<input type=”Radio” name = “gamelevel” Value = “Beginner” Checked = “true” />
<font color=#37448E>Beginner</font>
<input type=”Radio” name = “gamelevel” Value = “Intermediate” />
<font color=#37448E>Intermediate</font>
<input type=”Radio” name = “gamelevel” Value = “Advanced” />
<font color=#37448E>Advanced</font></div><br/><br/>
<input type = “button” value = ” start ” onClick=”startTimer()”/><br/>
<p>Seconds you have spent viewing this page so far:
<strong id = “soFar”>0</strong></p>
</form>
</body>
</html>