SCRIPT5009: undefined

Hi All,

This is my first attempt at coding JavaScript in a OOP way.  I get the following error not sure why:
SCRIPT5009: 'iceCreamApp' is undefined

$(document).ready(function() {
//Create name space so their will be no collisions if application grows
	var iceCreamApp = {};
	iceCreamApp.Truck = new Array();
	
	//Load data from list into array right away
	(function() {
		//IIFE() Imediately Invoked Function
		var url = "http://isaac.issharepoint.com/demo/_vti_bin/listdata.svc/IceCreamTrucks?$select=State,TownName,CountyName,IceCreamTrucks";
		$.ajax({
			url:url,
			type:"GET",
			dataType:"json",
			headers: {
                "accept": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },
			success: function(data) {
			//console.log(data.d);
				success(data);
			},
			error: function(data) {
				//failure(data);
				//console.log("ERROR");
			}
		})
			
		function success(data)
		{
			var iceCreamTrucks = data.d.results;
				for(var i = 0; i<iceCreamTrucks.length; i++)
				{
					iceCreamApp.Truck.push(new ICIItem({State:iceCreamTrucks[i].State,
					                           TownName:iceCreamTrucks[i].TownName,
											   CountyName:iceCreamTrucks[i].CountyName,
											   TruckCnt:iceCreamTrucks[i].IceCreamTrucks}));
				}
		}
	}());	
})


function ICIItem(params)
{
	this.TruckCnt = params.TruckCnt;
	if (this.TruckCnt > 5)
	{
		//do something
	}	
	this.State = params.State;
	this.TownName = params.TownName;
	this.CountyName = params.CountyName;
};
ICIItem.prototype.getUniqueType = function(Type)
{
	//This array will hold the unique states from the main array.
	var uniqueType = [];

	//loop through Array
	for (var i=0; i<iceCreamApp.Truck.length; i++)  //<-- SCRIPT5009: 'iceCreamApp' is undefined 
	{
		//if current item in array does not exist in my 'uniqueType' array, add it to 'uniqueType' array.
		if (($.inArray(iceCreamApp.Truck[i], uniqueType)) === -1)
		{
			uniqueType.push(iceCreamApp.Truck[i]);
		}
	}

	return uniquType;
}
ICIItem.prototype.getjQplotArray = function(uArray)
{
	var jqPlotDataArray = [];
	for(var i=0; i<uArray.lenght; i++)
	{
		var jqPlotData = {};
			jqPlotData.Type = uArray[i];
			jqPlotData.Count = 0;
		for (var x=0; x<iceCreamApp.Truck.length; x++)
		{
			if(uArray[i] == iceCreamApp.Truck[x])
			{
				jqPlotData.Count++;
			}
		}
		jqPlotDataArray[i] = jqPlotData;
	}
return jqPlotDataArray;		
};
	

function selectQry(list) 
{
	var qryVal = list.options[list.selectedIndex].value;	
	var uniqueTypeArray = ICIItem.prototype.getUniqueType(qryVal);	
	
	var getChartData = ICIItem.prototype.getjQplotArray(uniqueTypeArray);
	
	plotJqChart(getChartData);
}	

function plotJqChart(myData)
{
		var plot1 = jQuery.jqplot('chart1',[myData], {
		seriesDefaults: {
		   renderer: jQuery.jqplot.PieRenderer,
		   rendererOptions: {
		 	showDataLabels: true
		   }
		},
		legend: { show:true, location: 'e' }
	  });//end plot1
}

Open in new window


Look at Line 60
LVL 5
IsaacSharePoint Client Side DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian TaoSenior Business Solutions ConsultantCommented:
Your iceCreamApp is declared on row #3 in the $(document).ready block and so is its visibility.
Please move row #3 outside of any code-blocks and it should work.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IsaacSharePoint Client Side DeveloperAuthor Commented:
That worked. Thanks
0
Brian TaoSenior Business Solutions ConsultantCommented:
You're welcome.  Glad that helped.  Thanks for the points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.