I’m Having Issues With This Code, Its for a Random Generator App

  javascript
  1. I’m having issues with this code: it’s for a random generator app. The error says "Line: 186: setText() text parameter value (undefined) is not a uistring." I tried editing the code in a whole new way and it keeps saying it.
  2. I’m still having issues with this code: it’s for a random generator app. The error says "Line: 186: setText() text parameter value (undefined) is not a uistring." I tried editing the code in a whole new way and it keeps saying it.
var switchBestSelling = getColumn("Best-Selling Nintendo Switch Video Games", "Copies sold (M)");
var switchBestSellingName = getColumn("Best-Selling Nintendo Switch Video Games", "Title");
var switchRecentlyReleased = getColumn("Best-Selling Nintendo Switch Video Games", "Release date (1)");
var switchRecentlyReleasedName = getColumn("Best-Selling Nintendo Switch Video Games", "Title");

var filteredSwitchBestSelling = [];
var filteredSwitchBestSellingName = [];
var filteredSwitchRecentlyReleased = [];
var filteredSwitchRecentlyReleasedName = [];

// filter the lists and sets up the screen
listSetup();

// when the dropdown is changed, filter the lists and set up the screen
onEvent("salesDropdown", "change", function(){
  listSetup();
});
onEvent("releaseDateDropdown", "change", function( ) {
  listSetup(); 
});


function filterSwitch(){
  // clears the filtered lists
  filteredSwitchBestSelling = [];
  filteredSwitchBestSellingName = [];
  
  // gets the size from the dropdown
  var switchSales = getText("salesDropdown");
  
  // traverses the dogHeight List
  // if dogHeight and dogSize meet certain conditions
  // the corresponding names and images are stored in the filtered lists
  for(var i=0; i<switchBestSelling.length; i++){
    if(switchBestSelling[i] >= 19 && switchSales == "Sales Greater Than 19,000,000"){
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if(switchBestSelling[i] >= 18 && switchSales == "Sales Greater Than 18,000,000"){
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if(switchBestSelling[i] >= 17 && switchSales == "Sales Greater Than 17,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 16 && switchSales == "Sales Greater Than 16,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 15 && switchSales == "Sales Greater Than 15,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 14 && switchSales == "Sales Greater Than 14,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 13 && switchSales == "Sales Greater Than 13,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 12 && switchSales == "Sales Greater Than 12,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 11 && switchSales == "Sales Greater Than 11,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 10 && switchSales == "Sales Greater Than 10,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 9 && switchSales == "Sales Greater Than 9,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 8 && switchSales == "Sales Greater Than 8,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 7 && switchSales == "Sales Greater Than 7,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 6 && switchSales == "Sales Greater Than 6,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 5 && switchSales == "Sales Greater Than 5,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 4 && switchSales == "Sales Greater Than 4,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 3 && switchSales == "Sales Greater Than 3,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 2 && switchSales == "Sales Greater Than 2,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    } else if (switchBestSelling[i] >= 1 && switchSales == "Sales Greater Than 1,000,000") {
      appendItem(filteredSwitchBestSelling, switchBestSelling[i]);
      appendItem(filteredSwitchBestSellingName, switchBestSellingName[i]);
    }
  }
  // prints the list of video game names that match the value in the dropdown
  console.log(switchSales + " Video Games:");
  for (var j = 0; j < filteredSwitchBestSellingName.length; j++) {
    console.log(filteredSwitchBestSellingName[j] + "n");
  }
}

function filterSwitch2(){
  // clears the filtered lists
  filteredSwitchRecentlyReleased = [];
  filteredSwitchRecentlyReleasedName = [];
  
  // gets the size from the dropdown
  var switchDates = getText("releaseDateDropdown");
  
  // traverses the dogHeight List
  // if dogHeight and dogSize meet certain conditions
  // the corresponding names and images are stored in the filtered lists
  for(var i=0; i<switchRecentlyReleased.length; i++){
    if(switchRecentlyReleased[i] >= 39 && switchDates == "Release Date Later Than April 2020"){
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if(switchRecentlyReleased[i] >= 38 && switchDates == "Release Date Later Than March 2020"){
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if(switchRecentlyReleased[i] >= 37 && switchDates == "Release Date Later Than February 2020") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 36 && switchDates == "Release Date Later Than January 2020") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 35 && switchDates == "Release Date Later Than December 2019") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 34 && switchDates == "Release Date Later Than November 2019") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 33 && switchDates == "Release Date Later Than October 2019") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 32 && switchDates == "Release Date Later Than September 2019") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 31 && switchDates == "Release Date Later Than August 2019") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 30 && switchDates == "Release Date Later Than July 2019") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 29 && switchDates == "Release Date Later Than June 2019") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 28 && switchDates == "Release Date Later Than May 2019") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 27 && switchDates == "Release Date Later Than April 2019") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 26 && switchDates == "Release Date Later Than March 2019") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 25 && switchDates == "Release Date Later Than February 2019") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 24 && switchDates == "Release Date Later Than January 2019") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 23 && switchDates == "Release Date Later Than December 2018") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 22 && switchDates == "Release Date Later Than November 2018") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    } else if (switchRecentlyReleased[i] >= 21 && switchDates == "Release Date Later Than October 2018") {
      appendItem(filteredSwitchRecentlyReleased, switchRecentlyReleased[i]);
      appendItem(filteredSwitchRecentlyReleasedName, switchRecentlyReleasedName[i]);
    }
  }
  // prints the list of video game names that match the value in the dropdown
  console.log(switchDates + " Video Games:");
  for (var j = 0; j < filteredSwitchRecentlyReleasedName.length; j++) {
    console.log(filteredSwitchRecentlyReleasedName[j] + "n");
  }
}

// sets up the screen elements
function updateScreen(){
  var randomIndex = randomNumber(0, filteredSwitchBestSellingName.length-1);
  setText("output", filteredSwitchBestSellingName[randomIndex]);
}
function updateScreen() {
  var randomIndex2 = randomNumber(0, filteredSwitchRecentlyReleasedName.length-1);
  setProperty("output2", "text", filteredSwitchRecentlyReleasedName[randomIndex2]);
  
}
// sets up the lists and the screen
function listSetup(){
  filterSwitch();
  filterSwitch2();
  updateScreen();
}

Source: Ask Javascript Questions

One Reply to “I’m Having Issues With This Code, Its for a Random Generator App”

  • I have the same issue. I can not figure out how to get around it and i compared my code to a similar working code and it almost looks identical. Difference is, the other code works and i do not know why mine does not.

LEAVE A COMMENT