ar Normal = "normal";
prob we should keep it consistent. var NORMAL = 'normal'
ar Normal = "normal";
prob we should keep it consistent. var NORMAL = 'normal'
// switch (randomItem) { // case 1: // return SCR; // case 2: // return PAP; // case 3: // return STN; // default: // break; };
yes! definitely! switch case statements would be a good use case. makes code much more readable as well
var main = function (input)
Very good use of multiple helper functions to extract some of the game logic out. makes main function easier to read!
input
maybe we can think of how we can be more comprehensive. say if input == 'Scissors' --> maybe we can cover cases where user keys in capitalized input. prob we can convert all to lower case then compare to our winning conditions
var R_SCR = "reverse scissors"; var R_PAP = "reverse paper"; var R_STN = "reverse stone";
very good! i think its good to assign variables to input as ir can help prevent errors further down
var SCR = "scissors"; var PAP = "paper"; var STN = "stone";
this is good! always good to assign variables to prevent errors further on
} else if (userGuess == "scissors") { if (compOpt == "stone") { outputMesg = winMsg; winCount += 1; } else { outputMesg = lossMsg; lossCount += 1; }
another option would be considering the use of '&&' operator i.e. if (userGuess == 'scissors' && computerGuess =='paper') { //user wins ...} so you can reduce nested if functions as it might get confusing at times
var winMsg = "You win! "; var lossMsg = "You lose! "; var drawMsg = "It's a tie! ";
very nice! so u can keep reusing these variables
main = function (input
i like how your main function is clean and good use of helper functions!!
if (input == "regular" || input == "Regular")
can consider input.toLowerCase( ) to convert input to lower case and check if input == "regular"
var programHand = "Scissors";
so for programHand, everytime your random number changes, u dont have to re-declare it instead u can reassign the value instead. what i would do is say var programHand = ' ' if (randomHand == 1){ programHand = "Scissors" } else if (randomHand ==2){ programHand = 'Paper'}... return programHand
var main = function (userInput) { var programHand = randomProgramHand(); var userHand = userInput; var outcome = gameSPS(userHand, programHand); if (outcome == "win") { numPlayerWins += 1; totalGamesPlayed += 1; return winMssg(programHand, userHand, numPlayerWins, totalGamesPlayed); } else if (outcome == "lose") { totalGamesPlayed += 1; return loseMssg(programHand, userHand, numPlayerWins, totalGamesPlayed); } else if (outcome == "tied") { totalGamesPlayed += 1; return tiedMssg(programHand, userHand, numPlayerWins, totalGamesPlayed); } else if (outcome == "error") { return "Please key in 'scissors' 'paper' or 'stone' and try again"; } };
good that ur main function is short and u make use of helper functions. make ur code easier to read
if (numPlayerWins >= totalGamesPlayed / 2) return `The computer chose ${programHand} <br> You chose ${userHand} <br> <br> YOU WON! Congrats! <br> <br> Just type "scissors", "paper" or "stone" to play another round! <br> <br> Good Luck! So far you have been winning ${numPlayerWins}/${totalGamesPlayed} of games played. Pretty good!`; else if (numPlayerWins < totalGamesPlayed / 2) return `The computer chose ${programHand} <br> You chose ${userHand} <br> <br> YOU WON! Congrats! <br> <br> Just type "scissors", "paper" or "stone" to play another round! <br> <br> Good Luck! So far you have been winning ${numPlayerWins}/${totalGamesPlayed} of games played. Try to hit 50%! JYJY!`; };
this would naturally be an else statement?
so instead of else if, you could just do this
if ( numPlayerWins >= totalGamePlayer /2) {
return .... }
else {
return ....} or even better you could do this :
var winMsg = function (...){
if ( numPlayerWins >= totalGamePlayer /2) {
return .... }
return The computer chose....} --> https://medium.com/@rachelchervin/if-else-vs-if-return-using-implicit-returns-in-javascript-and-react-bbac63656e1b can read this for further explanation
GREAT WORK! saw that you did some styling as well! overall, clear logic flow and very good work :D
var main = f
good that your main function is short and some game logic is being extracted out into various functions
checkedInput != `Invalid output, please enter only scissors, paper or stone.` ) {
great validation
//username entry let userName = prompt(`Please enter your name!`, ``); var output = ``;
great use of prompt!
GREAT WORK :D very clear logic and consistent naming of functions and variables.
main = function (chosenGameMode, userChoice) { var myOutpu
good that u kept your main function short. like how you extract out your game logic into 2 other functions.
includes(userChoice)
nice use of array methods :D
GREAT WORK! overall clear logic and nice use of helper functions to extract some of the game logic :D
total_games = 0; player1_wins = 0; player1_loses = 0; player1_draws = 0; userName = "";
would be better if u can include the var keyword when declaring variables even it is for global state
otal_games
so for javascript, common convention is to use camelcase for naming variables and functions. https://www.w3schools.com/js/js_conventions.asp#:~:text=camelCase%3A,with%20many%20JavaScript%20library%20names.
for global variable you can use snake casing however we usually use uppercase. e.g. var TOTAL_GAMES = 0
snake case commonly used in python instead
checkInput(input1) == false
usually i would use "!" instead. i.e. if (!checkInput(input1)) https://softwareengineering.stackexchange.com/questions/405405/which-is-better-ifcondition-false-or-ifcondition
Overall, very clear good logic flow. i have nothing much to comment :D. naming of functions and variable is excellent and consistent as well NICE WORK HERE
var main = function (input) { if (input != "q") { return game(input); } else { begin = false; return `Thank you for playing!<br><br> This is your win-loss record! <br><br> ${showStats()}<br><br> Enter your name to play a new round!`; } };
wew so nice to see your main function short and making full use of helper functions to extract out some of the game logic. very goood!
Overall very good attempt and nice work!!
userinput != "scissors" || userinput!= "paper" || userinput!= "stone",
i was thinking maybe these 'OR' conditions can be changed to 'AND' so meaning. if user input is not scissors and input is not paper and input is not stone, then return invalid input.
if (userinput == "scissors" && randomChoose == "paper"){ userwin += 1 totalRounds += 1 return `${name}'s input is ${userinput} and program's input is ${randomChoose}.\n ${name} won ${userwin} /${totalRounds} time(s), with ${draw} draw(s).`;} if (userinput == "paper" && randomChoose == "stone"){ userwin += 1
maybe some of these if condition can be combined? eg. if (userInput == 'scissors' && randomChoose == 'paper') || (userInput == 'stone' && randomChoose == 'scissors') || (userInput == 'paper' && randomChoose == 'stone') { //player wins}
var name = prompt ("
nice use of prompt
var resultOutput = function ( flag, programInput, userInput, numRoll, numUserWin, numComWin, numDraws ) { if (flag == "draw") { return `The computer played ${programInput}. You played ${userInput}. It is a draw! <br><br> Statistics: <br> Number of games p
also good that the result output can be extracted out from the main function into helper function to print out the result statement.
overall clear logic and good that you extract out some of the codes and utlise helper functions to derive your game logic :D
(programInput == "scissors" && userInput == "scissors") || (programInput == "paper" && userInput == "paper") || (programInput == "stone" && userInput == "stone") ||
i was thinking whether we can just refactor and change these to programInput == userInput ..
nput.toLowerCase();
good that you considered this case
overall, great great work!! i like how you are usually various array methods such as includes, indexOf. Good that you are using resources outside of the course material. Also good that you extract out most of the code into various helper functions which makes the main code much more readable.
return choicesOutcome; } else { var choicesOutcome = `You lose! `; gamesPlayed++; return choicesOutcome; }
just wondering what would the outcome be if the input is undefined. meaning if user do not key in anynthing and just press click
includes
great that you are using array methods
inputLower = input.toLowerCase();
nice! good thinking to consider the scenarios where user keyed in uppercase input
if (!userName) { if (!input) { var gameInstructions = `Hi, please input your user name!`; ret
good that you prompted for the username! saw that you added some html elements to inform user to key in their user name! i was thinking may not need the !username, instead can just set the condition where !input then return the game instructions
Overall, i think very nice work!! good use of comments and clear logic. meaningful naming of variables and functions as well. i would think a mathematical approach will work as well as long as u comment it clearly what are the use cases.
playerWins = playerWins + 1; computerWins = computerWins;
if u want u can consider this -->playerWins += 1 as for computerWins u dont have to reassign again
playGame
very nice!! its good to extract this away and this makes ur main function much cleaner :)
Overall, very good job. logic is clear and good use of comments. code is readable and consistent naming convention.And also meaningful naming of variables and functions :)
i think it would be good to refactor this part(the whole switch case statment) and put it under a function. e.g. checkPlayerWin as we usually want our main function to be as clean as possible
var getGameMode = function(inpu
i like how u break down these into various helper functions. e.g. showSymbol, generateHand, getPlayerName!
if (inputHand == "paper") {return "🗒"} if (inputHand == "stone") {return "OO"}
i think can use if, else if and else.. since i think the inputHands are mutually exclusive
switch(input) { case "scissors":
i like the use of switch case statement. makes code cleaner and more readable!! usually i would assign variables e.g. var SCISSORS = 'scissors' to reduce likelihood of making error since u would be referencing a few times following in the switch case statement