<!doctype html>
<html>
<head>
<title>Who Am I Game - RJM Programming - July, 2018</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type='text/javascript'>

var clues=[
["Am a woman.", "I was born in 1938.","My job was as an actress.","I was a child star.","I gave birth to two children.","Those children were from different husbands.","I died in 1981.","I drowned in mysterious circumstances.","My birth name was Natalia Nikolaevna Zakharenko.","My name is Natalie Wood."],
["Am a woman.", "I was born in 1937.","I have been a politician.","I was born in the Czech Republic.","I have three children.","I emigrated to the United States in 1948.","I was first woman to have become the United States Secretary of State.","My middle names are Jana Korbel.","My name is Madeline Albright."],
["Am a man.", "I was born in 1869.","I have been a politician and studied law at the Inner Temple, London.","I had four children.","I was the leader of the Indian independence movement against British rule.","I was born and raised in a Hindu merchant caste family in coastal Gujarat, India.","I was assassinated in 1948.","My birth name was Mohandas Karamchand Gandhi.","My name is Mahatma Gandhi."],
["Am a man.", "I was born in 1879.","I was a scientist, a theoretical physicist.","I had three children.","I developed a principle of relativity.","From 1902 to 1909 I worked at the Swiss Patent Office in Bern, Switzerland.","I died in 1955 in the United States of America.","I received the 1921 Nobel Prize in Physics.","My name is Albert Einstein."]
];

var solved=false;
var ourset;
var iourset=0, jourset=0, kourset=0;
var score=0, goes=0, two=2;
var asguess=true;


var addto='origsnake1';

function guessas() {
var myguess=prompt('What is your guess for a first name and last name for this person (no initials please)?','');
if (myguess == null) myguess='';
if (myguess.trim() != '' && myguess.split(' ').length == 2) {
goes++;
if ((clues[iourset][eval(-1 + kourset)] + '~').toLowerCase().indexOf(' ' + myguess.toLowerCase() + '.~') != -1) {
asguess=false;
score+=Math.pow(2,kourset);
//alert('' + jourset + ' ... ' + score);
two=0;
document.getElementById(addto).click();
//alert(score);
}
document.getElementById('score').innerHTML='Score: ' + score + '/' + goes;
pickclueset();
} else {
goes++;
document.getElementById('score').innerHTML='Score: ' + score + '/' + goes;
}
}

function addthis(inputo) {
var nextto=eval(1 + eval(addto.replace('origsnake','')));
// Snake ...
// <a id='origsnake1' onclick="show('tdsnake',this);">Snake ... </a>
document.getElementById(addto).innerHTML+="</a><a title='Show me' style='text-decoration:underline;cursor:pointer;' id='origsnake" + nextto + "' onclick=\"show('tdsnake',this);\">" + inputo.value.replace(' ... ','').replace(' ...','').replace('...','') + " ... ";
addto='origsnake' + nextto;
}

function show(supervisor,curo) {
//alert("This innerHTML=" + curo.innerHTML + " and the overall table cell innerHTML=" + document.getElementById(supervisor).innerHTML);
if (two == 0) {
score-=Math.pow(2,jourset);
//alert('' + jourset + ' .+. ' + score);
jourset--;
} else {
score-=2;
guessas();
}
}

function pickclueset() {
two=2;
addto='origsnake1';
document.getElementById('tdsnake').innerHTML="<a title='Show me' style='text-decoration:underline;cursor:pointer;' id='origsnake1' onclick=\"show('tdsnake',this);\"></a>";
iourset=Math.floor(Math.random() * clues.length);
jourset=0;
kourset=clues[iourset].length;
solved=false;
askaway();
}

function askaway() {
if (!solved) {
document.getElementById('clue').innerHTML=clues[iourset][jourset];
document.getElementById('inputo').value=clues[iourset][jourset];
jourset++;
if (jourset >= kourset) {
addthis(document.getElementById('inputo'));
alert(clues[iourset][eval(-1 + kourset)] + ' Oh well, no score there.');
solved=true;
pickclueset();
} else {
addthis(document.getElementById('inputo'));
}
}
}
</script>
</head>
<body onload='pickclueset();'>
<h1>Who Am I Game</h1>
<h3>RJM Programming - July, 2018</h3>
<h4 id=score>Score: 0/0</h4>

<table style='width:100%;' border=20>
<tr><th>Need Another ...</th><th>Clue</th><th>Have a Guess</th><th>Clues so Far</th></tr>
<tr><td style='text-align:center;'><input style='background-color:pink;' type=button value="Need Next Clue" onclick="askaway();"></input><input type=hidden id=inputo value=''></input></td><td style='text-align:center;' id=clue></td><td style='text-align:center;'> <input style='background-color:pink;' type=button value="?" onclick=" if (asguess) { guessas(); } else { asguess=true; score+=two; show('tdsnake',document.getElementById(addto)); } "></input> </td><td id='tdsnake'><a title='Show me' style='text-decoration:underline;cursor:pointer;' id='origsnake1' onclick="show('tdsnake',this);"></a></td></tr>
</table>

</body>
</html>