Binary Search Tree

var total = 0;
var one;

function fun(){
	var min = 1;
	var max = 1000000;
	var guess;
	var number = Math.floor(Math.random() * max) + min;
	var counter = 0;
	
	while (guess !== number){
	        counter += 1;
		guess = Math.floor((min + max) / 2);
		if (number > guess){
			min = guess + 1;
		} else if (number < guess) {
			max = guess - 1;
		}
	}
	total += 1;
	if (counter === 1){
		one = 1;
	}
	
}
while (one !== 1){
	fun();
}
console.log(total)