<html>
<body>
<form>
<input type ="text" name="display" id="display" disabled >
<br>
<input type="button" id = "start" value="start" onclick="s()" >
<input type="button" id="ok" value="ok" onclick="o()" disabled="true">
</form>
</body>
</html>
<script type="text/javascript">
var num;
var attempt=1;
var x = document.getElementById("display");
x.disabled = false;
function s()
{
console.log("inside s");
num = Math.round(Math.random()* 100);
var o = document.getElementById("ok");
o.disabled = false;
console.log(num);
console.log(x.value);
}
function o()
{
var y = document.getElementById("display");
if(y.value == num)
{
alert("sucess"+" "+"attempts made are :" + attempt);
console.log("sucess");
y.disabled = true;
y.value="";
var o = document.getElementById("ok");
o.disabled = true;
}
else
{
if(y.value == " ")
{
alert("enter a number");
attempt++;
}
else
{
if(y.value > num)
{
alert("number is smaller then "+y.value);
attempt++;
y.value="";
}
else
{
alert("number is greater then "+y.value);
attempt++;
y.value = " ";
}}
}
}
</script>