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
61 changes: 58 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
var main = function (input) {
var myOutputValue = 'hello world';
return myOutputValue;
// this is a basic version of scissors paper stone //
// scissors beats paper //
// paper beats stone //
// stone beats scissors //
// if both parties choose the same object, it is a draw //
// user chooses input as scissors paper or stone //
// randomly return one of scissors paper or stone //
Comment on lines +1 to +7

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Comment] Nice use of pseudo code


var generateMove = function () {
// Generate random number between 1 and 3 //
var numPossibleMoves = 3;
var randomNum = Math.floor(Math.random() * numPossibleMoves) + 1;

// Return the word that corresponds to the relevant number //
if (randomNum == 1) {
return "scissors";
}
if (randomNum == 2) {
return "paper";
}
return "stone";
};
Comment on lines +9 to +22

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Comment] Good job to separate out this function by itself.


var main = function (userMove) {
var move = generateMove();
var standardMessage = `You played: ${userMove}. Computer played: ${move}.`;
// if both parties choose the same object, it is a draw //
if (move == userMove) {
return `${standardMessage} <br> <br> It's a draw! Please play again.`;
}
// scissors beats paper //

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Comment] Nice comments to show what the code is doing

if (move == "scissors" && userMove == "paper") {
return `${standardMessage} <br> <br> You lost! Please play again.`;
}
// paper beats stone //
if (move == "paper" && userMove == "stone") {
return `${standardMessage} <br> <br> You lost! Please play again.`;
}
// stone beats scissors //
if (move == "stone" && userMove == "scissors") {
return `${standardMessage} <br> <br> You lost! Please play again.`;
}
// scissors beats paper //
if (userMove == "scissors" && move == "paper") {
return `${standardMessage} <br> <br> You won! Please play again.`;
}
// paper beats stone //
if (userMove == "paper" && move == "stone") {
return `${standardMessage} <br> <br> You won! Please play again.`;
}
Comment on lines +40 to +50

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Suggestion]: You could have combined some of these IF conditions. Using || to combine all the losing cases. This would simplify your code.

// stone beats scissors //
if (userMove == "stone" && move == "scissors") {
return `${standardMessage} <br> <br> You won! Please play again.`;
}
// if user puts in undefined move //
if (userMove != "scissors" || "paper" || "stone") {
return `Your move is not valid! <br> <br> To play, please enter scissors, paper, or stone`;
}
};