blackbelt.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <script>////////////////
  8. //blackBelt
  9. var predictArray = {
  10. 1111: 1
  11. };
  12. var historyArr = [1, 1, 1, 1];
  13. var newValue = Math.round(Math.random());
  14. let newKey = "1111"
  15. let predictKey = []
  16. function blackBelt() {
  17. debugger
  18. var yourMove = +prompt("Your move 0 or 1");
  19. var answer;
  20. predictArray[newKey] = +yourMove;
  21. if (yourMove === 1 || yourMove === 0) {
  22. if (+newValue === yourMove){
  23. answer = confirm("I knew it. Let's try again");
  24. } else {
  25. answer = confirm ("You win. Let's try again");
  26. }
  27. historyArr.shift();
  28. historyArr.push(yourMove);
  29. newKey = "" + historyArr[0]+historyArr[1]+historyArr[2]+historyArr[3]
  30. if(predictKey.indexOf(newKey) == -1){
  31. newValue = Math.round(Math.random());
  32. } else {
  33. newValue = predictArray[newKey]
  34. }
  35. predictKey = Object.keys(predictArray)
  36. if(answer == true) {
  37. return blackBelt()
  38. }
  39. } else {
  40. alert ("Error. Try again")
  41. }
  42. }
  43. blackBelt();
  44. </script>
  45. </head>
  46. <body>
  47. </body>
  48. </html>