Skip to content
Open

SPS #351

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
37 changes: 35 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
var n = null;
Copy link

@leechuanxin leechuanxin Nov 20, 2021

Choose a reason for hiding this comment

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

It seems like n is ultimately not used anywhere, so it can be removed. While n is assigned to input in line 8, it doesn't look like you are returning n in the string in line 9.

If you are intending to use n to meet any user name requirement, it will be good to carry the user name string over to the output on lines 16, 27, 33, and 36.

Additionally, it will be better to name this variable clearly, for other readers / developers collaborating with you. username will be better.

var winCount = 0;
var lostCount = 0;
var drawCount = 0;
var count = 0;
var main = function (input) {
var myOutputValue = 'hello world';
return myOutputValue;
if (n == null) {
n = input;
return 'Hello ' + input;
}
++count;

Choose a reason for hiding this comment

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

Generally we prefer count += 1 instead of count++ or ++count. The ++ and -- syntaxes are very prone to human error, and you can learn more about this here: https://eslint.org/docs/rules/no-plusplus

if ((input == 'scissors') || (input == 'stone') || (input == 'paper')) {
var myOutputValue = getResult(input);
return myOutputValue;
};
return "The input options are scissors, stone or paper. Kindly select from these";
};

var getResult = function (input) {
console.log('you have input ' + input);
var handArray = ['stone', 'paper', 'scissors'];
var randomInteger = Math.floor(Math.random() * 3);
var chosenHand = handArray[randomInteger];
console.log('system has chosen ' + chosenHand);
if (input == chosenHand) {
++drawCount;
return ('System also chose ' + chosenHand + '. Its a Draw. No. of draws = ' + drawCount + '/' + count);

};
if (((input == 'scissors') && (chosenHand == 'paper')) ||
((input == 'paper') && (chosenHand == 'stone')) || ((input == 'stone') && (chosenHand == 'scissors'))) {
++winCount;
return 'System chose ' + chosenHand + '. You won :) No. of Wins = ' + winCount + '/' + count;
};
++lostCount;
return 'System chose ' + chosenHand + '. You lose. Try again :) No. of times lost ' + lostCount + '/' + count;
}