// Shows the text in the results text box so the user can see what rollercoaster they got
function updateScreen() {
var filteredRollercoasterName3List = [];
var randomRollerCoaster = randomNumber(filteredRollercoasterName3List.length - 1);
outputText = ((((" Hello, if you live in " + countryChoice) + " and want a rollercoaster that goes ") + speedChoice + "mph") + " with the material " + materialChoice) + " I recommend " + randomRollerCoaster ;
setText("informationBox", outputText);
}
One thing I see is that you have set the list of names to an empty list before you use it.
Another issue is the way that variables are created in two different ways. Consider for example filteredCountryList
. You declare as global here:
//filtered Lists
var filteredCountryList = [];
You then use that global variable here:
function filter() {
filteredCountryList = [];
Compare that to creating a local variable like this:
// Shows the text in the results text box so the user can see what rollercoaster they got
function updateScreen() {
var filteredRollercoasterName3List = [];
If you don’t recall the difference between local and global variables and what that does to you review the lessons. It is talked about extensively.
Once you have fixed that you will get a number. The problem is in this code:
var randomRollerCoaster = randomNumber(filteredRollercoasterName3List.length - 1);
outputText = ((((
" Hello, if you live in " + countryChoice) +
" and want a rollercoaster that goes ") + speedChoice + "mph") +
" with the material " + materialChoice) +
" I recommend " + randomRollerCoaster
You should be able to immediately see what the problem is. Also, drop the ()s. When you fix that it seems to work if you don’t change any of the drop-downs.
If you do change the drop-downs there is another problem:
//Picks one rollercoaster for the user
materialFilter();
speedFunction();
Ask yourself how often and when are these two functions called? How does that compare to when you change the drop-down values? Does that match up?