Advertisement
Guest User

Untitled

a guest
Jul 24th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function validate() {
  2.  
  3.     console.log('validate()');
  4.  
  5.     var x = Math.round(Math.random() * 10);
  6.  
  7.     var y = Math.round(Math.random() * 10);
  8.  
  9.     var answer = x+y;
  10.  
  11.     var text = "Are you a human check\nWhat is "+x+" + "+y+" equal?";
  12.  
  13.     var userAnswer = prompt(text,"");
  14.  
  15.     if (answer==userAnswer) {
  16.  
  17.         console.log("correct");
  18.  
  19.         return true;
  20.  
  21.     } else {
  22.  
  23.         console.log("not correct");
  24.  
  25.     var request = new XMLHttpRequest();
  26.  
  27.     request.open('GET', '/checkout_rejected', true);
  28.  
  29.     request.onload = function() {
  30.  
  31.             console.log("checkout_rejected status:"+this.status);
  32.  
  33.         };
  34.  
  35.  
  36.  
  37.         request.onerror = function() {
  38.  
  39.         // There was a connection error of some sort
  40.  
  41.             console.log("checkout_rejected onerror");
  42.  
  43.         };
  44.  
  45.     request.send();
  46.  
  47.     alert("In correct answer, please try again.");
  48.  
  49.         return false;
  50.  
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement