.search or indexOf function not working for New Hampshire

[Posts in the debugging category need to have the following pieces of information included in order to help other teachers or our moderator team best help you. Feel free to delete everything in brackets before posting your request for debugging help.]

I expect it to return “True” when I search for “New Hampshire” in the list. It works for all other states.
It is returning false when I choose “New Hampshire.”
I have tried using the trim method on the string. This did nothing to change it. I tried using the .search method and I have also tried the .includes method.

You have two spaces in “New Hampshire”. trim doesn’t remove embedded white space.

Where are the two spaces? I did not mention, I also tried copy and pasting New Hampshire directly from the data table and retyping New Hampshire. It still does not work.

I see now what you mean, but that was only in the console.log I was using for debugging. When I get input from the dropdown, it does not have 2 spaces and still does not work.

There is another problem. The space between New and Hampshire in the data base isn’t a space. It might be a tab.

What you need to do is open the data tab. Scroll to the right and press edit for Dartmouth Collage. Scroll to the left and find location. Delete the character between New and Hampshire, what ever it may be. Replace it with a real space.

Now it works. Here is the code I used

var locations = getColumn("Ivy League Universities","Location");
onEvent("dropdown2", "input", function( ) {
  var location = getText("dropdown2");
  var description = "not found";
  for(var i = 0; i < locations.length; i++){
   if(locations[i].includes(location)){
      description = locations[i];
   }
  }
  setText("label1",description);
});

I will open a bug for this.

1 Like

I just got a reply from Josh at code.org. That entry has been changed and it should work. You don’t need to change it.

@samantha.cruz There seems to be an issue with the table. I have referred this to the curriculum team. Expect a response soon.

1 Like

Thanks! I modified the data table and it works.