You win, rock beats scissor
+diff --git a/css/main.css b/css/main.css new file mode 100644 index 0000000..dae0eee --- /dev/null +++ b/css/main.css @@ -0,0 +1,46 @@ +body { + background: #302c2c; + font-family: 'Chilanka', cursive; + +} + +main { + background: gray; + margin: auto; + width: 50%; + padding: 30px; +} + + +button { + background: #ffdc8b; + border: 1px solid #716d6d; + padding: 20px; + width: 9em; + border-radius: 40px; +} + +button:focus { + outline: unset; +} + +button:hover { + background: #eaf64f; +} + +.btns-container { + display: flex; + justify-content: space-around; + background: #b3ae95; + padding: 10px; + +} + +#result { + background: burlywood; + text-align: center; + font-size: 1.8em; + padding: 20px; + + +} \ No newline at end of file diff --git a/debug.log b/debug.log new file mode 100644 index 0000000..d55aa40 --- /dev/null +++ b/debug.log @@ -0,0 +1,122 @@ +[0901/144401.283:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.286:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.286:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.286:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.286:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.287:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.287:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.287:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.287:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.287:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.287:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.287:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.287:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.287:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.287:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.287:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.287:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.287:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.288:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.289:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.289:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.289:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.290:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.291:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.291:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0901/144401.291:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.973:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.973:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.973:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.973:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.973:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.973:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.974:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.975:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.976:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.976:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.976:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.976:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.976:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.976:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.976:ERROR:crash_report_database_win.cc(469)] failed to stat report +[0922/115921.976:ERROR:crash_report_database_win.cc(469)] failed to stat report diff --git a/game.js b/game.js index 3d7e01b..f9bf849 100644 --- a/game.js +++ b/game.js @@ -1,3 +1,101 @@ -// Write all your code here -// Replace the contents of this file with your own code -console.log('Hello, world!'); +const choices = ["ROCK", "SCISSOR", "PAPER"]; + +function computerPlay() { + return choices[Math.floor(Math.random() * choices.length)]; +} + + +let counter = { + computer: 0, + user: 0, + tie: 0 +}; +let btns = document.getElementsByClassName('btns-container')[0]; +btns.addEventListener('click', function (e) { + if (e.target.tagName = 'BUTTON') { + let playerSelection = e.target.innerHTML; + let computerSelection = computerPlay(); + let result = playRound(playerSelection, computerSelection); + winCounter(result, playerSelection, computerSelection); + + } + +}); + + +let p = document.getElementById('result'); + +// track result +function winCounter(result, playerSelection, computerSelection) { + if (result == 'computer') { + counter.computer++; + p.innerHTML = ` You Lose ${computerSelection} Beats ${playerSelection}`; + } else if (result == 'user') { + counter.user++; + p.innerHTML = ` You Win ${playerSelection} Beats ${computerSelection}`; + } else if (result == 'tie') { + p.innerHTML = ` Tie ! ${playerSelection} VS ${computerSelection}`; + counter.tie++; + } + console.log("result is " + counter) + score.innerHTML = "Compter: " + counter.computer; + score.innerHTML += " | You:" + counter.user; + score.innerHTML += " Tie:" + counter.tie; + finalWinner(counter); +} + + + +let score = document.getElementById("score"); +// declare the winner who win in five rounds +function finalWinner(counter) { + resetCounter = false; + if (counter.computer >= 5) { + console.log('done computer win') + resetCounter = true; + p.innerHTML = "Congratulation You Won five rounds" + } else if (counter.user >= 5) { + console.log('done user win ') + resetCounter = true; + p.innerHTML = "Unfortunately lose in five rounds" + } + + //reset the counter + if (resetCounter) { + for (let prop in counter) + counter[prop] = 0; + + } +} + + + + + +function playRound(playerSelection, computerSelection) { + //playerSelection = playerSelection.toUpperCase(); + + //if( (playerSelection !== "ROCK") && (playerSelection !== "PAPER") && (playerSelection !== "SCISSOR") ){ + // return "INVALID INPUT"; + //} + + computerWin = false; + if (playerSelection === computerSelection) { + return "tie" + } else if (playerSelection == "ROCK" && computerSelection == "PAPER") { + computerWin = true; + } else if (playerSelection == "PAPER" && computerSelection == "SCISSOR") { + computerWin = true; + } else if (playerSelection == "SCISSOR" && computerSelection == "ROCK") { + computerWin = true; + } + + if (computerWin) + return 'computer'; + else + return 'user'; + +} + + +//game(); \ No newline at end of file diff --git a/index.html b/index.html index 947177f..187ae12 100644 --- a/index.html +++ b/index.html @@ -1,10 +1,27 @@ +
- -You win, rock beats scissor
+