Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
// 1. Generate random object: Scissors, Paper or Stone
var rollScissorPaperStone = function () {
var randomDecimal = Math.random() * 3;
var randomInteger = Math.floor(randomDecimal);
var signRolled = 0;
if (randomInteger == 0) {
signRolled = `scissors`;
}
if (randomInteger == 1) {
signRolled = `paper`;
}
if (randomInteger == 2) {
signRolled = `stone`;
}
return signRolled;
};
Comment on lines +2 to +16

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gd job abstracting this out into a function


const signs = [`scissors`, `paper`, `stone`];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice trying this out in advance, could have been used for assigning signedRolled in rollScissorsPaper stone function

var gamesCount = 0;
var userWonCount = 0;
var CompWonCount = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should follow camel-case convention just like your other variables

var drawCount = 0;

var main = function (input) {
var myOutputValue = 'hello world';
var randomSign = rollScissorPaperStone();
console.log(`computer generated ${randomSign}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good use of console logs

var myOutputValue = `Uh oh, I cannot read your message. <br>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input validation 👍

Please type one of the 3 options: scissors, paper or stone`;

// Outcome 1: Player and Computer draw
if (input == randomSign) {
gamesCount += 1;
drawCount += 1;
myOutputValue = `You chose ${input}. <br> The computer chose ${randomSign}. <br> You drawed ${drawCount} times. <br> Type "scissors" "paper" or "stone" to play another round!`;
}
Comment on lines +31 to +35

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job figuring this out


// Outcome 2: Player lost, Computer wins
if (
(input == signs[0] && randomSign == signs[2]) ||
(input == signs[1] && randomSign == signs[0]) ||
(input == signs[2] && randomSign == signs[1])
) {
gamesCount += 1;
CompWonCount += 1;
myOutputValue = `You chose ${input}. <br> Computer chose ${randomSign}. <br> You lost ${CompWonCount} out of ${gamesCount} games, and drawed ${drawCount} times. Keep trying! <br> Type "scissors" "paper" or "stone" to play another round!`;
}

// Outcome 3: Player wins, Computer lost
if (
(input == signs[0] && randomSign == signs[1]) ||
(input == signs[1] && randomSign == signs[2]) ||
(input == signs[2] && randomSign == signs[0])
) {
gamesCount += 1;
userWonCount += 1;
myOutputValue = `You chose ${input}. Computer chose ${randomSign}. <br> You won ${userWonCount} out of ${gamesCount} games, and drawed ${drawCount} times. Feeling lucky? <br> Type "scissors" "paper" or "stone" to play another round!`;
}
return myOutputValue;
};