<commit_before>var answer = document.getElementById('answer');
var attempt = document.getElementById('attempt');

function guess() {
    let input = document.getElementById('user-guess');
    //add functionality to guess function here
    if(answer.length == 0 || attempt.length == 0){
    	setHiddenFields();
	}

	if(!vaildateInput(input.value)){
		return false;
	}

	if(getResults(input.value)){
		setMessage("You win! :)");
		showAnswer(true);
		showReplay();
	}else if(!getResults(input.value) && attempt >= 10){
		setMessage("You Lose! :(");
		showAnswer(false);
		showReplay();
	}else{
		setMessage("Incorrect, try again.");
	}


	attempt++;
}

//implement new functions here

function setHiddenFields(){
	attempt = 0;
	answer = Math.floor(Math.random() * 9999).toString();
	
	while(answer.length < 4){
		answer = "0" + answer;
	}	

}

function setMessage( newMessage ){
	var id = document.getElementById('message');
	id.innerHTML(newMessage);
}

function vaildateInput( input ){
	if(input.length == 4){
		return true;
	} else {
		setMessage("Guesses must be exactly 4 characters long.");
		return false;
	}
}

function getResults( param ){
	var div1 = document.getElementById('results');
	var guessedCorrectly = 0;

	for(var i = 0, x = param.length; i < x; i++){
		div1.innerHTML += "<div class=\"row\"><span class=\"col-md-6\">'" + param + "'</span><div class=\"col-md-6\">";
		
		if(param.charAt(i) == answer.charAt(i)){
			div1.innerHTML += "<span class=\"glyphicon glyphicon-ok\"></span>";
			guessedCorrectly++;
		} else if(answer.includes(param.charAt(i))){
			div1.innerHTML += "<span class=\"glyphicon glyphicon-transfer\"></span>";
		} else {
			div1.innerHTML += "<span class =\"glyphicon glyphicon-remove\"></span>";  		
		}

		div1.innerHTML += "</div>\n</div>"

		return (guessedCorrectly == answer.length)
	} 
}

function showAnswer( param ){
	var code = document.getElementById('code');
	code.innerHTML = answer;
	if(param){
		code.className += "success";
	} else {
		code.className += "failure";
	}
}

function showReplay(){<commit_msg>Fixed some DOM elements and major bugs<commit_after>var answer = document.getElementById('answer');
var attempt = document.getElementById('attempt');

function guess() {
    let input = document.getElementById('user-guess');
    //add functionality to guess function here
    if(answer.value.length == 0 || attempt.value.length == 0){
    	setHiddenFields();
	}

	if(!vaildateInput(input.value)){
		return false;
	}

	var results = getResults(input.value);

	if(results){
		setMessage("You win");
		showAnswer(true);
		showReplay();
	}else if(!results && attempt.value >= 10){
		setMessage("You Lose!");
		showAnswer(false);
		showReplay();
	}else{
		setMessage("Incorrect, try again.");
	}


	attempt.value++;
}

//implement new functions here

function setHiddenFields(){
	attempt.value = 0;
	var x = Math.floor(Math.random() * 10000).toString();
	
	while(x.length < 4){
		x = "0" + x;
	}

	answer.value = x;	

}

function setMessage( newMessage ){
	 document.getElementById('message').innerHTML = newMessage;
}

function vaildateInput( input ){
	if(input.length == 4){
		return true;
	} else {
		setMessage("Guesses must be exactly 4 characters long.");
		return false;
	}
}

function getResults( param ){
	var div1 = document.getElementById('results');
	var guessedCorrectly = 0;
	var inner = "";
	
	inner += "<div class=\"row\"><span class=\"col-md-6\">" + param + "</span><div class=\"col-md-6\">";
	
	for(var i = 0, x = param.length; i < x; i++){
		
		
		if(param.charAt(i) == answer.value.charAt(i)){
			inner += "<span class=\"glyphicon glyphicon-ok\"></span>";
			guessedCorrectly++;
		} else if(answer.value.indexOf(param.charAt(i)) > -1){
			inner += "<span class=\"glyphicon glyphicon-transfer\"></span>";
		} else {
			inner += "<span class=\"glyphicon glyphicon-remove\"></span>";  		
		}
		
	}
	
	inner += "</div></div>"
	div1.innerHTML += inner;

	return (guessedCorrectly == answer.value.length)

} 


function showAnswer( param ){
	var code = document.getElementById('code');
	code.innerHTML = "<strong>" + answer.value + "</strong>";
	if(param){
		code.className += " success";
	} else {
		code.className += " failure";
	}
}

function showReplay(){
{'fraction_non_alphanumeric': 0.18216229004021764, 'fraction_numerical': 0.010409273716583865, 'mean_word_length': 4.045346062052506, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2180098', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1363, 'n_words': 309}