var no,count,total,s;
var myword="";
var curr,flag,currN;
var score=0;

function start()
{
 flag=s=0;
 no=count=score=0;
 total=21;
 document.getElementById('score').innerHTML="Score : "+score;
 next1();
}

function next1()
{
 s=1;
 console.log('a');
 flag=0;
 document.getElementById('iii').src="images/invisible.png";
 document.getElementById('skip').innerHTML="Skip";
 document.getElementById('skip').style.color="black";
 no++;
 if(no>=total-1)
  document.getElementById('skip').innerHTML="Finish";
 if(no==total)
 {
  if(score>100)
   alert("Congratulations! You are done with this task :) :) \n\nSCORE : "+score+"\n\n Kindly continue to next game MoneyMaker.");
  else
   alert("Congratulations! You are done with this task :) :) \n\nSCORE : "+score+"\n\nKindly continue to next game MoneyMaker. You can also try again to improve your score.");
  no--;
  for(var v=1;v<5;v++)
   {
	document.getElementById('n'+v).disabled=true;
    document.getElementById('n'+v).style.color='black';
   }
 }
 else
 {
   for(var v=1;v<5;v++)
   {
	document.getElementById('n'+v).disabled=false;
    document.getElementById('n'+v).style.color='black';
   }
 document.getElementById('q').innerHTML = "Question : "+no+"/20";
  currN = Math.floor(Math.random()*4);
  switch(currN)
  {
   case 0:
    var v1 = Math.floor(Math.random()*10);
    var v2 = Math.floor(Math.random()*10);
	document.getElementById('v1').placeholder=v1;
	document.getElementById('v2').placeholder=v2;
	document.getElementById('res').placeholder=(v1+v2);
	break;
   case 1:
    var v1 = Math.floor(Math.random()*10);
    var v2 = Math.floor(Math.random()*10);
	if((v1-v2)>=0)
	{
	 document.getElementById('v1').placeholder=v1;
	 document.getElementById('v2').placeholder=v2;
	 document.getElementById('res').placeholder=(v1-v2);
	}
	else
	{
	 document.getElementById('v1').placeholder=v2;
	 document.getElementById('v2').placeholder=v1;
	 document.getElementById('res').placeholder=(v2-v1);
	}
	break;
   case 2:
    var v1 = Math.floor(Math.random()*10);
    var v2 = Math.floor(Math.random()*10);
	document.getElementById('v1').placeholder=v1;
	document.getElementById('v2').placeholder=v2;
	document.getElementById('res').placeholder=(v1*v2);
	break;
   case 3:
    var v1 = Math.floor(Math.random()*10);
	if(v1==0) v1=2;
    var v2 = Math.floor(Math.random()*10);
	if(v2==0) v2=3;
	document.getElementById('v1').placeholder=v1*v2;
	document.getElementById('v2').placeholder=v2;
	document.getElementById('res').placeholder=v1;	
  }
  console.log(Math.floor(currN/2)+1);
 }
}

function check( param )
{
 var v1,v2,res;
 v1=v2=res=0;
 v1 = document.getElementById('v1').placeholder;
 v2 = document.getElementById('v2').placeholder;
 res = document.getElementById('res').placeholder;
 var f=0;
 
   if(param==0 && (Math.floor(v1)+Math.floor(v2) == res)) f=1;
   if(param==1 && (Math.floor(v1)-Math.floor(v2) == res)) f=1;
   if(param==2 && (Math.floor(v1)*Math.floor(v2) == res)) f=1;
   if(param==3 && (Math.floor(v1)/Math.floor(v2) == res)) f=1;
 if(f==1)
 {
  if(s==1)
    score = score + 10;
   s=0;
   for(var v=1;v<5;v++)
	 document.getElementById('n'+v).disabled=true;
   document.getElementById('n'+(1+param)).style.color='green';
   flag=1;
   document.getElementById('score').innerHTML="Score : "+score;
   document.getElementById('skip').style.color="green";
   document.getElementById('skip').innerHTML="Next";
   document.getElementById('iii').style.visibility="visible";
   document.getElementById('iii').src="images/correct.png";
 }
 else
 {
  document.getElementById('n'+(param+1)).disabled = true;
   document.getElementById('iii').style.visibility="visible";
   document.getElementById('iii').src="images/incorrect.png";
   document.getElementById('skip').style.color="black";
   document.getElementById('skip').innerHTML="Skip";
   score = score - 1;
   document.getElementById('score').innerHTML="Score : "+score;
 }
}

function clr()
{
 score = score - 4 ;
 document.getElementById('score').innerHTML="Score : "+score;
 myword="";
}

function exit()
{
 if(confirm("Do you really want to exit?"))
  window.location="index.html";
}

function restart()
{
if(confirm("Do you really want to restart game?"))
 {
  start();
 }
}

function skip()
{
 next1();
}