var currentNumber = 1;
var lastFibonacci = "0";
var currentFibonacci = "1";
var endingString = "aaa";

function getNextFib()
{
	currentNumber++;
	var oldLastFibonacci = lastFibonacci;
	lastFibonacci = currentFibonacci;
	return currentFibonacci = currentFibonacci.add(oldLastFibonacci);
}

function getNextFibUI()
{
	var nextVal = getNextFib();
	$("#currentNumber").text( currentNumber );
	$("#currentVal").text( nextVal );
	window.scrollTo(0, 0);
}

function clearScore()
{
	currentNumber = 1;
	lastFibonacci = "0";
	currentFibonacci = "1";
	endingString = "aaa";
	updateUI();
}

function updateUI()
{
	$("#currentNumber").text( currentNumber );
	$("#currentVal").text( currentFibonacci );
	window.scrollTo(0, 0);
}

String.prototype.endsWith = function(suffix) {
    return this.indexOf(suffix, this.length - suffix.length) !== -1;
};

function getPaddingString(length)
{
	var string = "";
	
	for(var i = 0; i < length; i++)
	{
		string += "0";
	}
	
	return string;
}

String.prototype.add = function(number){
	var thisLastDigit = this.length;
	var thatLastDigit = number.length;
	var carried = 0;
	var finalString = "";
	
	var tempThis = "0" + this;
	number = "0" + number;
	
	var padding = thisLastDigit - thatLastDigit;
	
	var paddingString = getPaddingString(Math.abs(padding));
	
	if(padding > 0)
	{
		number = paddingString + number;
	}
	else
	{
		tempThis = paddingString + tempThis;
	}
	
	for(var i = Math.min(thisLastDigit, thatLastDigit) + Math.abs(padding); i > -1; i--)
	{
		var newNum = tempThis.charCodeAt(i) + number.charCodeAt(i) + carried - 96;
		if(newNum >= 10)
		{
			carried = ( newNum - (newNum % 10) ) / 10;
			newNum = newNum % 10;
		}
		else
		{
			carried = 0;
		}
		
		finalString = newNum + finalString + "";
	}
	
	if(finalString[0] == "0"){ finalString = finalString.substr(1); }
	
	return finalString;
};

function getNext10000FibsUI()
{
	endingString = $("#ending").val();
	for(var i = 0; i < 9999 ; i ++)
	{
		getNextFib();
		if( (currentFibonacci + "").endsWith( endingString )){
			updateUI();
			return;
		}
	}
	getNextFibUI();
}

function getNthFib(n)
{

}

@@ -1826,24 +1826,249 @@
 String;%0A%7D;%0A%0A
+function correctString(type, aimString)%0A%7B%0A%09if(type = %22ends%22)%7B return (currentFibonacci).endsWith( aimString ); %7D%0A%09else if(type = %22contains%22)%7B return (currentFibonacci.indexOf(aimString) == 1 );%7D%0A%09else%7B%0A%09%09return false;%0A%09%7D%0A%7D%0A%0A%0A
 function get
@@ -2083,16 +2083,20 @@
 0FibsUI(
+type
 )%0A%7B%0A%09end
@@ -2189,42 +2189,22 @@
 if( 
-(currentFibonacci + %22%22).endsWith( 
+correctString(
 endi
@@ -2211,18 +2211,18 @@
 ngString
- 
 )
+ 
 )%7B%0A%09%09%09up

Update script.js