Advertisement
snickers12341

Untitled

Aug 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Function scope example</title>
  6. <!DOCTYPE html>
  7. <html>
  8.  
  9. <head>
  10.  
  11. </style>
  12. </head>
  13.  
  14. <body>
  15.  
  16. <script>
  17. // function determintetoupper(playerselection){
  18. // if(playerselection-)
  19.  
  20. //}
  21. var nextcall = false;
  22.  
  23. function determinator(game, secondvar) {
  24. if (game()) {
  25. nextcall = true;
  26. if (nextcall) {
  27. var rounds = 5;
  28. rounds--;
  29. rounds = rounds;
  30. nextcall = false;
  31. console.log('there are ' + rounds + 'remaining');
  32.  
  33. }
  34.  
  35. }
  36. }
  37. var playerwinner;
  38. var computerwinner;
  39.  
  40. function getRandomInt(max) {
  41. return Math.floor(Math.random() * Math.floor(max));
  42. }
  43. var computer = 'the computer winner is ';
  44. var human = 'the human winner is';
  45.  
  46. function computerplay() {
  47. var rock = 'rock';
  48. var paper = 'paper';
  49. var scissors = 'scissors';
  50. var selector = getRandomInt(3);
  51. if (selector == 0) {
  52. //return rock
  53. return rock;
  54. } else if (selector == 1) {
  55. //return scissors
  56. return scissors;
  57. } else if (selector == 2) {
  58. //return paper
  59. return paper;
  60. } else {
  61. console.log('error')
  62. }
  63. }
  64.  
  65. //mistake is probably at the conditionals sedction
  66. // typos mistakes in this function fixed
  67. //HUGE MISTAKE IN THE SECTION WHERE I DEFINE THE FUNCTION AND THERE IS AN IF STATEMNT fixed
  68.  
  69.  
  70.  
  71.  
  72. function playRound(playerselection, computerselection) {
  73. if (playerselection == 'rock' && computerselection == 'scissors') {
  74.  
  75. return human + playerselection;
  76.  
  77. } else if (playerselection == 'scissors' && computerselection == 'paper') {
  78. return human + playerselection;
  79. } else if (playerselection == 'paper' && computerselection == 'rock') {
  80. return human + playerselection;
  81. } else if (computerselection == 'paper' && playerselection == 'rock') {
  82. return computer + computerselection;
  83. } else if (computerselection == 'scissors' && playerselection == 'paper') {
  84. return computer + computerselection;
  85. } else if (computerselection == 'rock' && playerselection == 'scissors') {
  86. return computer + computerselection;
  87. } else if (playerselection == computerselection) {
  88. console.log('draw')
  89. }
  90.  
  91.  
  92.  
  93. }
  94.  
  95. function game() {
  96.  
  97.  
  98. //var oldvalue;
  99. //oldvalue=rounds;
  100. //var newvalue=oldvalue-1;
  101. //rounds=newvalue;
  102.  
  103. var playerselection = prompt();
  104. var computerselection = computerplay();
  105. if (playerselection === playerselection.toUpperCase() || playerselection === playerselection.toLowerCase()) {
  106. playRound(playerselection, computerselection);
  107. var result = playRound(playerselection, computerselection);
  108. alert(result);
  109. determinator(game, nextcall);
  110. }
  111.  
  112. }
  113. game();
  114. </script>
  115. </body>
  116.  
  117. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement