Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.2 kB
2
Indexable
Never
<button onclick="
        playGame('papir');
        ">Papir</button>

        <button onclick="
        playGame('kamen')
        ">Kamen</button>

        <button onclick="
        playGame('makaze');
        ">Makaze</button>

        <script>
            function playGame(playerMove) {

            computerMove = pickCompterMove();

            let result = '';

             if (playerMove === 'makaze') {
                if (computerMove === 'papir') {
                    result = 'Cestitam pobedio si';
                } else if (computerMove === 'kamen') {
                    result = 'Izgubio si'
                } else if (computerMove === 'makaze'){
                    result = 'Nereseno je.'
                }
             } else if (playerMove === 'papir'){ 
                if (computerMove === 'papir') {
                    result = 'Nereseno je.';
                } else if (computerMove === 'kamen') {
                     result = 'Cestitam, pobedio si.'
                } else if (computerMove === 'makaze'){
                    result = 'Izgubio si.'
                    }
             } else if (playerMove === 'kamen') {
                if (computerMove === 'papir') {
                    result = 'Izgubio si';
                } else if (computerMove === 'kamen') {
                    result = 'Nereseno je.'
                } else if (computerMove === 'makaze'){
                    result = 'Cestitam pobedio si.'
        }
            };
                alert(`Izbarali ste ${playerMove}. Kompjuter je izabrao ${computerMove}. ${result}`);        
        }
            function pickCompterMove() {
                const randomNumber = Math.random();
                let computerMove ='';
                if (randomNumber > 0 && randomNumber < 1 / 3) {
                        computerMove = 'papir';
                    } else if (randomNumber >= 1 / 3 && randomNumber < 2 / 3) {
                        computerMove = 'kamen';
                    } else if (randomNumber >= 2 / 3 && randomNumber < 1) {
                        computerMove = 'makaze';
                    }

                    return computerMove;
                };
        </script>
Leave a Comment