var words=new Array();
words[0]="BUY";
words[1]="ONE";
words[2]="OUR";
words[3]="OWN";
words[4]="SPY";
words[5]="DRY";
words[6]="END";
words[7]="ERR";
words[8]="RUN";
words[9]="FEW";
words[10]="ICE";
words[11]="JAM";
words[12]="JOB";
words[13]="LAB";
words[14]="YET";
words[15]="WIG";
words[16]="TRY";
words[17]="TEN";
words[18]="SEA";
words[19]="SIX";
words[20]="SIN";

var descr=new Array();
descr[0] = "to purchase";
descr[1] = "NUMBER 1";
descr[2] = "belonging to us";
descr[3] = "belonging to oneself";
descr[4] = "to watch secretly";
descr[5] = "to reduce moisture";
descr[6] = "to finish or close";
descr[7] = "to make a mistake";
descr[8] = "to move quickly";
descr[9] = "not many";
descr[10] = "to cool with frozen water";
descr[11] = "to block up";
descr[12] = "to do piece work";
descr[13] = "a laboratory";
descr[14] = "in addition";
descr[15] = "to provide with a hairpiece";
descr[16] = "to attempt";
descr[17] = "NUMBER 10";
descr[18] = "an ocean";
descr[19] = "NUMBER 6";
descr[20] = "to commit a moral offence";

var no,count,total;
var myword="";
var curr,wrong;
var score=0;

function start()
{
 currN=Math.floor(Math.random()*20);
 console.log('started');
 no=count=score=0;
 total=21;
 document.getElementById('score').innerHTML="Score : "+score;
 next();
}

function f1( param )
{
 myword = myword + param;
 console.log(myword);
 document.getElementById('output').placeholder=myword;
 if(curr==myword)
 {
   alert("'"+words[currN]+"' MEANS '"+descr[currN]+"'");
   score = score + 10;
   document.getElementById('score').innerHTML="Score : "+score;
   document.getElementById('iii').style.visibility="visible";
   document.getElementById('iii').src="images/correct.png";
   document.getElementById('skip').style.color='green';
   document.getElementById('skip').innerHTML='Next';
   for(v=1;v<=26;v++)
    document.getElementById('n'+v).disabled = true;
	next();
 }
 else if(myword.length >=3)
 {
  console.log('oh' + document.getElementById('iii').src);
  score = score - 1;
   document.getElementById('score').innerHTML="Score : "+score;
   
   document.getElementById('iii').style.visibility="visible";
   document.getElementById('iii').src="images/incorrect.png";
   
   document.getElementById('skip').innerHTML='Retry';
   for(v=1;v<=26;v++)
    document.getElementById('n'+v).disabled = true;
   wrong=1;
 }
}

function next()
{
 if(document.getElementById('skip').innerHTML=="Retry")
 {
   wrong=0;
  for(v=1;v<=26;v++)
    document.getElementById('n'+v).disabled = false;
	document.getElementById('skip').color='black';
   document.getElementById('skip').innerHTML='Skip';
   document.getElementById('skip').style.color='black';
   document.getElementById('skip').innerHTML='Skip';
  document.getElementById('iii').style.visibility="hidden";
  clr();
 }
 else
 {
  wrong=0;
  for(v=1;v<=26;v++)
    document.getElementById('n'+v).disabled = false;
	document.getElementById('skip').color='black';
   document.getElementById('skip').innerHTML='Skip';
   document.getElementById('skip').style.color='black';
   document.getElementById('skip').innerHTML='Skip';
  document.getElementById('iii').style.visibility="hidden";
 no++;
 if(no==total)
 {
  if(score>100)
  alert("Congratulations! You are done with this task :) :) \n\nSCORE : "+score+"\n\nKindly continue to next game WordTest."); 
  else
  alert("Congratulations! You are done with this task :) :) \n\nSCORE : "+score+"\n\nKindly continue to next game WordTest. You can also try again to improve your score.");
   
  for(v=1;v<=26;v++)
    document.getElementById('n'+v).disabled = true;
   document.getElementById('skip').innerHTML='Finish';
  no--;
 }
 else
 {
 if(no==total-1)
   document.getElementById('skip').innerHTML='Finish';
 currN = (currN+2)%19;
 curr=words[currN];
  document.getElementById('output').placeholder="";  
 document.getElementById('find').placeholder = "Find "+words[currN];
 document.getElementById('q').innerHTML = "Question : " + no +"/20";
 curr=words[currN];
 myword="";
 }
 }
}

function clr()
{
 myword="";
 document.getElementById('output').placeholder="";
}

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