Student is creating this in app lab and when we hit the save button the species is undefined I think their is something wrong with her species function but not certain. code is below.
https://studio.code.org/projects/applab/T0BWK1Nn07GJvH4MbBsIc3gXk4MZX1MYVuKdrHdVdPQ
//creating generic variables
var species= getColumn(“Dinosaur Fossils”,“Species”);
var year= getColumn(“Dinosaur Fossils”, “Year Found”);//year found, ranges from 1905 to 2016
var motility= getColumn(“Dinosaur Fossils”, “Motility”);
var diet= getColumn(“Dinosaur Fossils”, “Diet”);
var country= getColumn(“Dinosaur Fossils”, “Country”);
//code start
var filteredCountryIndexes=;
var possibleSpecies=;
//code for homescreen
onEvent(“startButton”, “click”, function( ) {
setScreen(“americaMapScreen”);
});
//code for mapScreen
onEvent(“canada”, “click”, function(){
for (var i = 0; i < country.length; i++) {
if (country[i]== “Canada”){
appendItem(filteredCountryIndexes, i);
}
}
setScreen(“featureChoiceScreen”);
});
onEvent(“unitedStates”, “click”, function(){
for (var i = 0; i < country.length; i++) {
if (country[i]== “United States”){
appendItem(filteredCountryIndexes, i);
}
}
setScreen(“featureChoiceScreen”);
});
onEvent(“mexico”, “click”, function(){
for (var i = 0; i < country.length; i++) {
if (country[i]== “Mexcio”){
appendItem(filteredCountryIndexes, i);
}
}
setScreen(“featureChoiceScreen”);
});
//code for featureChoiceScreen
onEvent(“saveButton”, “click”, function( ) {
randomDinosaur();
setScreen(“dirtScreen”);
setText(“speciesText”, "Species: " + species[possibleSpecies[randomNumber(0, possibleSpecies.length)]]);
});
onEvent(“goBackButton”, “click”, function( ) {
setScreen(“americaMapScreen”);
filteredCountryIndexes=;
});
//function
function randomDinosaur(){
var specificYear= getText(“yearDropdown”);
var specificMobility= getText(“motilityDropdown”);
var specificDiet= getText(“dietDropdown”);
var age=;
if (specificYear==“1901-1910”){
appendItem(age, 1901);
appendItem(age, 1910);
}
else if(specificYear==“1911-1920”){
appendItem(age, 1911);
appendItem(age, 1920);
}
else if(specificYear==“1921-1930”){
appendItem(age, 1921);
appendItem(age, 1930);
}
else if(specificYear==“1931-1940”){
appendItem(age, 1931);
appendItem(age, 1940);
}
else if(specificYear==“1941-1950”){
appendItem(age, 1941);
appendItem(age, 1950);
}
else if(specificYear==“1951-1960”){
appendItem(age, 1951);
appendItem(age, 1960);
}
else if(specificYear==“1961-1970”){
appendItem(age, 1961);
appendItem(age, 1970);
}
else if(specificYear==“1971-1980”){
appendItem(age, 1971);
appendItem(age, 1980);
}
else if(specificYear==“1981-1990”){
appendItem(age, 1981);
appendItem(age, 1990);
}
else if(specificYear==“1991-2000”){
appendItem(age, 1991);
appendItem(age, 2000);
}
else if(specificYear==“2001-2010”){
appendItem(age, 2001);
appendItem(age, 2010);
}
else if(specificYear==“2011-2020”){
appendItem(age, 2011);
appendItem(age, 2020);
}
for (var i=0; i<filteredCountryIndexes.length; i++){
if((year[filteredCountryIndexes[i]])>=age[0]&&(year[filteredCountryIndexes[i]])<=age[1]){
if(specificMobility==motility[filteredCountryIndexes[i]]){
if(specificDiet==diet[filteredCountryIndexes[i]]){
appendItem(possibleSpecies,filteredCountryIndexes[i]);
}
}
}
}
}