Try this. Its simple but you get the idea. Rest you should try to accomplish yourself.
var clicks = 0;
document.getElementById('button').onclick = function(){
clicks++;
if(clicks == 5) {
window.location.href="www.yourlink.com";
}
}
<button id="button">
Click
</button>
solved How to write Java script that advances to a link after a link has been clicked “X” # of times [closed]