[SOLVED] Wikipedia api arrays response

Hello everyone,
i’m working on my Wikipedia Viewer and I don’t understand why when I search words like “ca”,“cia”,“er”,“qw” and so on, the first result element is the closest result, without paragraph. This is my codepen, sorry for background-colors but i’m trying to understand layout and with colours is simple.

You need to start i at 1 instead of zero.

Your solution don’t works.

Originally I thought you were returning your search value into your array which is why I said to start it one step later. However, now I see that’s not what is happening; “ca” doesn’t return a paragraph because there is no paragraph to return. Try looking up ca on Wikipedia page, you’ll get some kind of disambiguation page. I think that is why you aren’t getting a paragraph.

Hey try taking the encodeURIComponent out of line 4 and just store the plain “keyword” value into searchKeys. I forked your code pe,n left i at 0 and took the encoding out and now it’s only giving me the results with paragraphs. @stefalber

I can’t see your forks :confused: maybe I wrong something because my code still returns me results without paragraph. :frowning:

I wasn’t linking my forks. All you have to do is remove the word on the line I specified. It was an anonymous fork so it didn’t get saved.
image

I’ve done it again here’s the screenshot @stefalber let me know if it works for you.

Still doesn’t work. Maybe I have to change my request.

That’s weird because I edited your forked code pen. That picture is surrounded by the rest of your code I just only wanted to screenshot the part that was being changed and it worked for me. Can you screenshot your code and the results of the search?

free thias is my code and my request.

You haven’t removed the encodeURIComponent in this picture. Can you remove it so you searchKeys variable looks like the picture I posted then search for “ca” and let me know if it stops referencing the one without paragraphs?

It doesn’t stop it. It’s this codepen.

That is incredibly frustrating. I’ll fork it again and try something else.

Obviously, something I did the first time was wrong and accidentally produced the right result. I think what the problem is you want to not return any results that are going to lead to a disambiguation page (the titles with no paragraphs). So this code sets up a condition that only adds the result that contains a paragraph to the page. Hopefully, this is the intended behaviour you desire.

1 Like

That’s works well. Thank you for the time spent on me. :slight_smile:

1 Like