Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 8 additions & 42 deletions static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ var getrandom = function()
{
return Math.floor(Math.random()*(3-0+1)+0);
}





//assignment function
var assign = function(){

var v = document.querySelector("#table");
var randii=getrandom();
var v = document.querySelector("#table");
var randii=getrandom();
var randjj=getrandom();
if(v.rows[randii].cells[randjj].innerHTML==" ") {
v.rows[randii].cells[randjj].innerHTML="2";
}
else{
assign();

}//switching colors
}
//switching colors
for(var i=0 ; i<=3 ; i++){
for(var j=0 ; j<=3 ; j++){

Expand All @@ -37,26 +34,17 @@ else{
case "32":v.rows[i].cells[j].style.backgroundColor="#F67C5F"
break;
case "64":v.rows[i].cells[j].style.backgroundColor="#F65E3B"
break
break;
default:
v.rows[i].cells[j].style.backgroundColor="#CDC1B4"





}

}
}
else
{
v.rows[i].cells[j].style.backgroundColor="#CDC1B4"
}
}
}



}
var newg=function(){
console.log("in");
Expand All @@ -67,8 +55,6 @@ var seperate = function(i){
myrand=getrandom();
if(myrand==i){
seperate();


}
console.log("myrand = ",myrand );
console.log("given = ",i );
Expand Down Expand Up @@ -150,17 +136,11 @@ console.log("this, innerHTML = ", this.innerHTML);
for(var l=3 ; l>=0 ; l--){ //Just did some work with replacing random variable on only a blank space and down is almost complete..
for(var k=3 ; k>=0 ; k--){
if(v.rows[l].cells[k].innerHTML!=" "){


movedown(l,k,v,s);



}}

}


assign(v);
}

Expand All @@ -181,20 +161,13 @@ for(var l=0 ; l<=3 ; l++){ //Just did some work with replacing random variable
}

assign(v);


}




if(event.keyCode == 39 || k==="right"){
console.log("in right");
for(var l=3 ; l>=0 ; l--){ //Just did some work with replacing random variable on only a blank space and down is almost complete..
for(var k=3 ; k>=0 ; k--){
if(v.rows[l].cells[k].innerHTML!=" "){


moveright(l,k,v,s);


Expand Down Expand Up @@ -349,16 +322,9 @@ var gameover=function(){

}
if(k==9){
console.log("GAME OVER");
console.log("GAME OVER!!");
}

}








window.addEventListener('load' , startthis);