Wikipedia Viewer: Window not opening on 'click' event for random article


Hi All!

In the wikipedia viewer exercise, new window won’t open when I click “View Random Wikipedia Article”.

Instead, it opens as soon as I hit run (something I don’t want it to do), but then never works when I click the button.

What am I doing wrong?

Here is a link to my codepen:



You can do this

$(document).ready(function () {

or just a plain a href

<a href="" target="_blank">Random Stuff</a>


.on has two required parameters - an event, and a function that runs code when the event fires:

Your code:


^^ is missing the function.

You can fix this by adding an anonymous function:

$("#randomBtn").on('click', function() {'');

Or a named function:

$("#randomBtn").on('click', openRandomWikipediaArticle);

function openRandomWikipediaArticle() {'');

You could also use HTML instead of JavaScript with a hyperlink styled like a button:

<a href="" class="btn btn-default" target="_blank">
  View Random Wikipedia Article