var sl = new Array('q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m');
var cl = new Array('Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M');

var no=0;
var myword="";
var curr="RUN";
var total=1;
var rand;
var flag,count,total;

function start( )
{
 total=30;
 count=score=0;
 flag=1;
 document.getElementById('score').innerHTML="Score : "+score;
 document.getElementById('skip').innerHTML = "Skip";
 document.getElementById('skip').style.color="Black";
 next();
}

function check(param)
{
 if(document.getElementById(param).innerHTML == cl[rand])
 {
  if(flag==1)
  {
   score = score+10;
   flag=0;   
   document.getElementById('iii').style.visibility="visible";
   document.getElementById('iii').src="images/correct.png";
   document.getElementById('l1').disabled=true;
   document.getElementById('l2').disabled=true;
   document.getElementById('l3').disabled=true;
   document.getElementById('l4').disabled=true;
  }   
  document.getElementById('score').innerHTML="Score : "+score;
  document.getElementById('skip').innerHTML = "Next";
  if(count>=total)
  document.getElementById('skip').innerHTML="Finish";
  document.getElementById('skip').style.color="Green";
  
 }
 else
 {
  score = score-1;
  document.getElementById('score').innerHTML="Score : "+score;
  document.getElementById('iii').style.visibility="visible";
  document.getElementById('iii').src="images/incorrect.png";
  document.getElementById(param).disabled=true;
 }
}

function next()
{
   document.getElementById('l1').disabled=false;
   document.getElementById('l2').disabled=false;
   document.getElementById('l3').disabled=false;
   document.getElementById('l4').disabled=false;
 count++;
 if(count>total)
 {
  if(score>100)
  alert("Congratulations! You are done with this task :) :) \n\nSCORE : "+score+"\n\nKindly continue to next game LearnWords.");
  else
  alert("Congratulations! You are done with this task :) :) \n\nSCORE : "+score+"\n\nKindly continue to next game LearnWords. You can also try again to improve your score.");
 }
 else
 {
  document.getElementById('q').innerHTML= "Question : "+count+"/30";
  document.getElementById('iii').style.visibility="hidden";
  flag=1;
  console.log('next');
  document.getElementById('skip').innerHTML = "Skip";
  document.getElementById('skip').style.color="Black";
  rand = (Math.floor(Math.random()*26) + 2)%26;
  document.getElementById('letter1').placeholder=sl[rand];
  var rand2 = (Math.floor(Math.random()*4)+2)%4 +1;
  document.getElementById('l'+rand2).innerHTML = cl[rand];
  var te = rand;
  for(i=1;i<=4;i++)
  {  
   if(i!=rand2)
   {
    te = (te+5)%26 ;
    document.getElementById('l'+i).innerHTML = cl[te];
   }
  }
 }
if(count>=total)
  document.getElementById('skip').innerHTML="Finish";
}

function btn2Fun()
{
 next();
}

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();
 }
}