Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <meta charset="utf-8">
- <title>Function scope example</title>
- <!DOCTYPE html>
- <html>
- <head>
- </style>
- </head>
- <body>
- <script>
- // function determintetoupper(playerselection){
- // if(playerselection-)
- //}
- var nextcall = false;
- function determinator(game, secondvar) {
- if (game()) {
- nextcall = true;
- if (nextcall) {
- var rounds = 5;
- rounds--;
- rounds = rounds;
- nextcall = false;
- console.log('there are ' + rounds + 'remaining');
- }
- }
- }
- var playerwinner;
- var computerwinner;
- function getRandomInt(max) {
- return Math.floor(Math.random() * Math.floor(max));
- }
- var computer = 'the computer winner is ';
- var human = 'the human winner is';
- function computerplay() {
- var rock = 'rock';
- var paper = 'paper';
- var scissors = 'scissors';
- var selector = getRandomInt(3);
- if (selector == 0) {
- //return rock
- return rock;
- } else if (selector == 1) {
- //return scissors
- return scissors;
- } else if (selector == 2) {
- //return paper
- return paper;
- } else {
- console.log('error')
- }
- }
- //mistake is probably at the conditionals sedction
- // typos mistakes in this function fixed
- //HUGE MISTAKE IN THE SECTION WHERE I DEFINE THE FUNCTION AND THERE IS AN IF STATEMNT fixed
- function playRound(playerselection, computerselection) {
- if (playerselection == 'rock' && computerselection == 'scissors') {
- return human + playerselection;
- } else if (playerselection == 'scissors' && computerselection == 'paper') {
- return human + playerselection;
- } else if (playerselection == 'paper' && computerselection == 'rock') {
- return human + playerselection;
- } else if (computerselection == 'paper' && playerselection == 'rock') {
- return computer + computerselection;
- } else if (computerselection == 'scissors' && playerselection == 'paper') {
- return computer + computerselection;
- } else if (computerselection == 'rock' && playerselection == 'scissors') {
- return computer + computerselection;
- } else if (playerselection == computerselection) {
- console.log('draw')
- }
- }
- function game() {
- //var oldvalue;
- //oldvalue=rounds;
- //var newvalue=oldvalue-1;
- //rounds=newvalue;
- var playerselection = prompt();
- var computerselection = computerplay();
- if (playerselection === playerselection.toUpperCase() || playerselection === playerselection.toLowerCase()) {
- playRound(playerselection, computerselection);
- var result = playRound(playerselection, computerselection);
- alert(result);
- determinator(game, nextcall);
- }
- }
- game();
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement