47 Matching Annotations
  1. Jul 2022
    1. // 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

    2. 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

    3. 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

    1. } 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

    1. 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

    2. 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

    3. 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

  2. Jun 2022
    1. 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.

    1. 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

    1. 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

    2. 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!

    1. 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.

    2. 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}

    1. 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.

    2. (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 ..

    1. 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.

    2. 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

    3. 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

    1. 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.

    2. playerWins = playerWins + 1; computerWins = computerWins;

      if u want u can consider this -->playerWins += 1 as for computerWins u dont have to reassign again

    1. 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 :)

    2. 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

    3. 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

    4. 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