Help with Code on Unit 5 Hackathon project

Can someone help me figure out why the variable is undefined on line 40 when it defined on line 26?

Thanks

1 Like

Just looking quickly at your code, what I see is that you call getRandomFossil(); on line 22 of your code. That is before you declare the variable on line 26. It is best practice to declare all your global variables at the top of your program.

1 Like

Thanks. I appreciated it and figured it out

I also need help figuring out this syntak.error on line 65
var BirthYears = getColumn(“African American Inventors and Scientists”, “Date of birth / death”);
var inventors = getColumn(“African American Inventors and Scientists”, “Name”);
var occupation = getColumn(“African American Inventors and Scientists”, “Occupation(s)”);
var inventions = getColumn(“African American Inventors and Scientists”, “Inventions / accomplishments”);

//create filtered lists
var filteredBirthYears = ;
var filteredInventors = ;
var filteredOccupations = ;
var filteredInventions = ;
var filterUnknown = ;
var updateScreenUnknown = ;
var updateScreen1700s = ;
var updateScreen1800s = ;
var updateScreen1900s = ;
var filtered1800s = ;
var filtered1900s = ;

//add onevents for buttons
onEvent(“1700sButton”,“click”, function( ) {
filter1700s();
updateScreen1700s();
});
onEvent(“1700sGoBack”, “click”, function( ){
setScreen(“home”);
});
onEvent(“1800sButton”, “click”, function( ){
filtered1800s();
updateScreen1800s();
});
onEvent(“1800sGoBack”, “click”, function( ){
setScreen(“home”);
});
onEvent(“1900sButton”, “click”, function( ){
filtered1900s();
updateScreen1900s();
});
onEvent(“1900sGoBack”, “click”, function( ){
setScreen(“home”);
});
onEvent(“unknownButton”, “click”, function( ){
filterUnknown();
updateScreenUnknown();
});
onEvent(“unknownGoBack”, “click”, function(){
setScreen(“home”);
});

//reset FilteredLists

function resetFilteredLists(){
filteredBirthYears = ;
filteredInventors = ;
filteredOccupations = ;
filteredInventions = ;
}

//filter function
function filter1700s()

for (var i=0; i < inventors.length; i++){
var firstTwoNumbers = birthYears[i].substring(0,2);
if (firstTwoNumbers === “17”){
appendItem(filteredBirthYears, birthYears[i]);
appendItem(filteredInventors, inventors[i]);
appendItem(filteredOccupations, occupations[i]);
appendItem(filteredInventions, inventions[i]);
}
}

//filter function
function filter1800s()

resetFilteredLists();
for (var i=0; i < inventors.length; i++){
var firstTwoNumbers = birthYears[i].substring(0,2);
if (firstTwoNumbers = “18”){
appendItem(filteredBirthYears, birthYears[i]);
appendItem(filteredInventors, inventors[i]);
appendItem(filteredOccupations, occupations[i]);
appendItem(filteredInventions, inventions[i]);
}
}

//filter function
function filter1900s()

resetFilteredLists();
for (var i=0; i < inventors.length; i++){
var firstTwoNumbers = birthYears[i].substring(0,2);
if (firstTwoNumbers = “19”){
appendItem(filteredBirthYears, birthYears[i]);
appendItem(filteredInventors, inventors[i]);
appendItem(filteredOccupations, occupations[i]);
appendItem(filteredInventions, inventions[i]);
}
}

function filterUnknown(){
resetFilteredLists();
for (var i=0; i < inventors.length; i++){
var firstTwoNumbers = birthYears [i].substring(0,2);
if (firstTwoNumbers != “19” && firstTwoNumbers != “18” && firstTwoNumbers != “17”){
appendItem(filteredBirthYears, birthYears[i]);
appendItem(filteredInventors, inventors[i]);
appendItem(filteredOccupations, occupations[i]);
appendItem(filteredInventions, inventions[i]);
}
}
}

//update screen function
function updateScreen1700s(){
setScreen(“1700s”);
var textOutput = “”;
for (var i=0; i<filteredInventors.length; i++){
var newIndex = i+1;
textOutput = textOutput + newIndex +". NAME: " +filteredInventors[i]+ ", "+ filteredBirthYears[i]
}
setText(“1700sOutput”, textOutput);
}

function updateScreen1800s(){
setScreen(“1800s”);
var textOutput = “”;
for (var i=0; i<filteredInventors.length; i++){
var newIndex = i+1;
textOutput = textOutput + newIndex +". NAME: " +filteredInventors[i]+ ", "+ filteredBirthYears[i]
}
setText(“1800sOutput”, textOutput);
}

function updateScreen1900s(){
setScreen(“1900s”);
var textOutput = “”;
for (var i=0; i<filteredInventors.length; i++){
var newIndex = i+1;
textOutput = textOutput + newIndex +". NAME: " +filteredInventors[i]+ ", "+ filteredBirthYears[i]
}
setText(“1900sOutput”, textOutput);
}

function updateScreenUnknown(){
setScreen(“unknown”);
var textOutput = “”;
for (var i=0; i<filteredInventors.length; i++){
var newIndex = i+1;
textOutput = textOutput + newIndex +". NAME: " +filteredInventors[i]+ ", "+ filteredBirthYears[i]
}
setText(“unknownOutput”, textOutput);
}

Hi @william.smith ,

To help keep this thread organized and for dedicated attention to your issue, please submit your issue as a new post. Please also make sure to follow the protocol you’ll see with steps like linking to your project so we can run it and explore deeper and give recommendations.

Thanks and I look forward to your post.