From 68ad3725040241833d173b7adfe11dd3f7200292 Mon Sep 17 00:00:00 2001 From: azizck Date: Mon, 2 Sep 2019 13:39:53 -0400 Subject: [PATCH 1/2] done --- debug.log | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ game.js | 38 +++++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 debug.log diff --git a/debug.log b/debug.log new file mode 100644 index 0000000..215c506 --- /dev/null +++ b/debug.log @@ -0,0 +1,61 @@ +[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 diff --git a/game.js b/game.js index 3d7e01b..376cd20 100644 --- a/game.js +++ b/game.js @@ -1,3 +1,39 @@ // 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)] ; +} + +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 win ! because ${computerSelection} beats ${playerSelection}`; + else + return `You Win because ${playerSelection} beats ${computerSelection}`; + +} + + function game (){ + for(let i=0; i<5; i++){ + playerSelection=prompt("Enter your choice"); + let result = (playRound(playerSelection,computerPlay())); + alert(result); + } +} +game(); \ No newline at end of file From d9a589a66f6a17a3aa2dc042a5e00b8336e7d97d Mon Sep 17 00:00:00 2001 From: azizck Date: Sun, 22 Sep 2019 14:52:15 -0400 Subject: [PATCH 2/2] Done --- css/main.css | 46 +++++++++++++++++++ debug.log | 61 +++++++++++++++++++++++++ game.js | 124 ++++++++++++++++++++++++++++++++++++++------------- index.html | 25 +++++++++-- 4 files changed, 221 insertions(+), 35 deletions(-) create mode 100644 css/main.css 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 index 215c506..d55aa40 100644 --- a/debug.log +++ b/debug.log @@ -59,3 +59,64 @@ [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 376cd20..f9bf849 100644 --- a/game.js +++ b/game.js @@ -1,39 +1,101 @@ -// Write all your code here -// Replace the contents of this file with your own code -const choices = ["ROCK","SCISSOR","PAPER"]; -function computerPlay(){ - return choices[Math.floor(Math.random()*choices.length)] ; +const choices = ["ROCK", "SCISSOR", "PAPER"]; + +function computerPlay() { + return choices[Math.floor(Math.random() * choices.length)]; } -function playRound(playerSelection,computerSelection){ - playerSelection = playerSelection.toUpperCase(); - if( (playerSelection !== "ROCK") && (playerSelection !== "PAPER") && (playerSelection !== "SCISSOR") ){ - return "INVALID INPUT"; + +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); + } - 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 win ! because ${computerSelection} beats ${playerSelection}`; - else - return `You Win because ${playerSelection} beats ${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); } - function game (){ - for(let i=0; i<5; i++){ - playerSelection=prompt("Enter your choice"); - let result = (playRound(playerSelection,computerPlay())); - alert(result); + + +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; + } } -game(); \ No newline at end of file + + + + + +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 @@ + - - Rock, Paper, Scissors! - + + + Rock, Paper, Scissors! + + + + +
+
+ + + +
+
+

You win, rock beats scissor

+
+
sdfsadfsd
+
- + + \ No newline at end of file