Avatar of Isaac
Isaac
Flag for United States of America asked on

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
JavaScriptjQuery

Avatar of undefined
Last Comment
Brian Tao

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Brian Tao

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Isaac

ASKER
That worked. Thanks
Brian Tao

You're welcome.  Glad that helped.  Thanks for the points.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck