Skip to content

Instantly share code, notes, and snippets.

@justinobney
Created November 12, 2015 21:24
Show Gist options
  • Save justinobney/73908b0f36ad85568545 to your computer and use it in GitHub Desktop.
Save justinobney/73908b0f36ad85568545 to your computer and use it in GitHub Desktop.
function onSuccess(){
$('form').attr('action', 'foo');
}
function makeEquation(successCallback){
var words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'];
var left = Math.floor(Math.random() * 10 + 1);
var right = Math.floor(Math.random() * 10 + 1);
var question = words[left-1] + ' + ' + words[right-1] + ' = ? (example: one + two = 3)';
return {
question: question,
verify: function verify(answer){
var answer == left + right;
if(successCallback){
(successCallback || function(){}).call()
}
}
};
}
var captcha = makeEquation(onSuccess);
captcha.question; // "ten + six = ? (example: one + two = 3)"
captcha.verify(16) // calls success callback
captcha.verify(14) // does nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment