Updated version of the first version of Rock, Paper, Scissors for The Odin Project Assignment.
-
For the first submission
script_v1.js
, the result can be seen inconsole
panel. -
The second version comes with User Interface that live on here.
The first version of the game will take the player choice from the alert prompt. It will keep running until player or computer get scores 5.
- Create
getComputerChoice
function:- Create an array for the computer selection which consist of
Rock
,Paper
andScissors
.
- Create an array for the computer selection which consist of
- Create a function that plays a single round called
playRound
which takes parameterplayerSelection
andcomputerSelection
as an input:- Create the comparison between the
playerSelection
andcomputerSelection
by usingif...else
- for example, if
playerSelection
==computerSelection
, the result should be tie. - if
playerSelection
== Rock ANDcomputerSelection
== Scissors, the result should be player win... and so on.. - note: Rock beats Scissors, Scissors beats Paper, and Paper beats Rock
- update the score for each round.
- Create the comparison between the
- Create a function that shows the who is the winner called
finalScore()
by usingif...else
statement:- if
playerScore
>computerScore
, return Player as the winner. - if
computerScore
>playerScore
, return Computer as the winner.
- if
- Create
game()
function as a main function to begin the game:- Using
while
loop to iterate the function until one of the score is equals to 5. - In this loop, get the player selection using
prompt()
method. - Convert the input that the player type to capital letter at the front and small letters for the rest.
- Call the
getComputerChoice()
function to getcomputerSelection
. - Increase the
round
to the iteration. - After one of the players reach the score 5, call the
finalScore()
which terminates the game.
- Using
- Modify the
index.html
andstyle.css
file. - Modify the
playRound()
function by simplifying theif...else
statement. - Create a new function to update the game interface with the round results called
updateGameInterface()
. Parameters that need to be updated:- round
- playerChoice
- computerChoice
- playerScore
- computerScore
- result
- Change the
game()
function to only start the game when the player click their choice calledhandleWeaponClick()
- if one of the score is not equals to 5 yet, call the
getComputerChoice()
to get thecomputerSelection
. - Update the user interface
updateGamesInterface()
. - Once one of the score is equals to 5, call the
finalScore()
function.
- if one of the score is not equals to 5 yet, call the
- Add event listeners to get the player choice.