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 = "$select=State,TownName,CountyName,IceCreamTrucks";
			headers: {
                "accept": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
			success: function(data) {
			error: function(data) {
		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,

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)

	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])
		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);

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
IsaacSharePoint Client Side DeveloperAsked:
Who is Participating?

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

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.

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
Brian TaoSenior Business Solutions ConsultantCommented:
You're welcome.  Glad that helped.  Thanks for the points.
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

From novice to tech pro — start learning today.