Untitled
2 years ago in Plain Text
DOCTYPE html>
<meta charset="UTF-8">
<html>
<body id="everything">
Guess the number:
<div id="display_output">
output
</div>
<form>
<input type="text" id="the_number" maxlength=6 >
</form>
</body>
</html>
<script type="text/javascript">
console.log("Thus begins the game!");
document.getElementById("everything").style.fontSize=45;
var iterfation=2;
var have_out="";
function get_random_number(number_size){
var got_number="";
for(var i=0;i< number_size;i++){
got_number += Math.floor((Math.random()*7)+1).toString();
}
return got_number;
}
function guessed_in_random(guessed_number,random_number){
var b = "";
console.log(guessed_number+" rn:" + random_number +" Thus begins the game!");
// 0 is no, 1 is yes, 2 is 1-3 , 3 is 4-6
for (var j=0; j < random_number.length; j++){
if (guessed_number[j] == random_number[j])
b += "1";
else if (j < 3)
b += "2";
else if (j >3 && j < 7)
b += "3";
else
b += "0";
}
return b;
}
function get_ball_array(random_number, guessed_number){
var ball_array=["&#x25CB","&#x25CF","&#x25D0","&#x25D1"];
var final_balls=[];
var guessed = guessed_in_random(guessed_number, random_number);
console.log(guessed +" Thus finalized the game!");
for (var k=0;k<guessed.length;k++){ // ball types
final_balls+= ball_array[guessed[k]];
}
return final_balls;
}
function get_balls(){
if (typeof have_out=="undefined"){
var have_out= "hah";
console.log("FUCK");
}
if(typeof iterfation=="undefined")
var iterfation=0;
if (iterfation == 7)
iterfation = 1;
else iterfation++;
random_number = get_random_number(6);
console.log(random_number.toString() +" got random!!");
if(typeof guessed_number=="undefined")
var guessed_number="123456";
else
var guessed_number=document.getElementById("display_output").value;
got_balls = get_ball_array(random_number,guessed_number);
console.log(got_balls +" got balls!!");
have_out+= "<br>Iteration "+iterfation.toString() + ": "+ got_balls;
document.getElementById("display_output").innerHTML=have_out;
}
//get_balls.iteration = 1;
//get_balls.have_out="";
var x = document.getElementById("the_number");
x.addEventListener("onblur", get_balls());
//document.getElementById("display_output").innerHTML="&#x25CB &#x25CF &#x25D0";
//document.getElementById("display_output").style.fontSize=45;
document.getElementById("the_number").style.fontSize=45;
//document.getElementById("the_number").onblur= new get_balls();
</script>