Rock paper scissors

I want to build a self playing rock paper scissors … can some one help me out?

my question is commented in the code block below above the call to the function im trying to get to work

//The Variables for the players
const player = "Ian";
const miAi = "Computer";

//The Variables for the moves
//const choice1 = "lapis";
//const choice2 = "papyrus";
//const choice3 = "scalpellus"

// eventual refactor of moves variables \\1 - 2 - 3\\

const movesList = [
  (choice1 = "lapis"),
  (choice2 = "papyrus"),
  (choice3 = "scalpellus")
];
const results = [
  `${miAi} wins! ${miAi}  chose ${choice2} and ${player} chose ${choice1}.`,
  `${miAi}  wins! ${miAi} chose ${choice3} and ${player} chose ${choice2}.`,
  `${miAi}  wins! ${miAi}  chose ${choice1} and ${player} chose ${choice3}.`,
  `${player} wins! The player chose ${choice2} and ${miAi}  chose ${choice1}.`,
  `${player} wins! The player chose ${choice3} and ${miAi}  chose ${choice2}.`,
  `${player} wins! The player chose ${choice1} and ${miAi}  chose ${choice3}.`
];

let playerMove = function () {
  let index1 = Math.floor(Math.random() * 3);
  let selection1 = movesList.at(index1);
  return selection1;
};

let miAiMove = function () {
  let index2 = Math.floor(Math.random() * 3);
  let selection2 = movesList.at(index2);
  return selection2;
};

const decisionMaker = function () {
  playerMove();
  miAiMove();
};
const move = (decisionMaker()) => {
  if (playerMove === choice1 && miAiMove === choice2) {
    console.log(results[0]);
  }

  if (playerMove === choice2 && miAiMove === choice3) {
    console.log(results[1]);
  }

  if (playerMove === choice3 && miAiMove === choice1) {
    console.log(results[2]);
  }
  ///////////////////////////////////////////

  if (miAiMove === choice1 && playerMove === choice2) {
    console.log(results[3]);
  }

  if (miAiMove === choice2 && playerMove === choice3) {
    console.log(results[4]);
  }

  if (miAiMove === choice3 && playerMove === choice1) {
    console.log(results[5]);
  }
};
// As i said ... the code code design isnt quite finished yet
// Here I am as far as trying to just get "result" to  store //and display the respective calls to // the results array
// How do i make the line up of helper functions interact with //my set of if statements
// so that the line below will log that value to the //console
// then i will worry about storing  the  conditional array value into the result variable on my own
console.log(move());

Where have you gotten stuck so far?

here…haha… at least on my ide the code i posted won’t log the appropriate message…

In my .012% experience … this code looks like the call to move SHOULD reach into the results array and pull out data stored at a specific index … as relegated by the if statements

like this code doesn’t work… nothing comes out… i muck around for hours and the best i can do is get the WHOLE HELPER FUNCTION to display to the console… but otherwise… errors or no output at all

also i commented my question above the last line of code

You should be getting a Syntax Error for this line.

1 Like

i was worried about that line… but my ide is even formatting my JS so … can i get a hint?

its acting like nothing is wrong

also ive tried it removing the “()”… it still doesnt work

you can call function( lets call it a) inside another function(lets call it b). And if you do so, there is no need to pass a function as a parameter to b
you did something like that actually in your code, the decisionMaker declaration would be example

1 Like
const move = () => {
decisionMaker()
  if (playerMove === choice1 && miAiMove === choice2) {
    console.log(results[0]);
  }

How are you testing your code? I ran it through node and got a Syntax Error right away.

That’s a good start. But you have other issues as well.

What type of value is playerMove and miAiMove? Does the following really make sense:

if (playerMove === choice1 && miAiMove === choice2) {
1 Like

…in the ide for my school… its precourse work i i finished and am building off of for practise…
i just ran it through replit… i see it now
im actually already drafting a email to the IT team about it…
… low key i might have still needed the help though… the error makes sense because YOU just walked me through it <3 100
but only cuz a that… i think

ok looking at it… hold on

i feel like your telling me it doesnt but

but playerMove and miAimove are strings randomly pulled from movesList and they enter into move after decisonMaker calls them and are compared to the variable name i gave to each index value in movesList … right?

I am missing any code to handle a tie i just noticed also

before this line, try to log out playerMove
and also playerMove()

with the prans i get the string; without i get the function

1 Like

cool, so in your if statement you’re trying to compare what?

1 Like

OOOHH OOOOOOHH OOOHHHHHHHHHHHHH MY GOSH

If i could leave this posted until im done(i still have to convert the output of the if statements for starters) in case i hit anymore potholes … i would really appreciate it

The code that works :slight_smile:

i still want it to run again if it comes out to a tie
right after logging its message…
im trying to figure that out now

//The Variables for the players
const player = "Ian";
const miAi = "Computer";

//The Variables for the moves
//const choice1 = "lapis";
//const choice2 = "papyrus";
//const choice3 = "scalpellus"

// eventual refactor of moves variables \\1 - 2 - 3\\
let result = "";

const movesList = [
  (choice1 = "lapis"),
  (choice2 = "papyrus"),
  (choice3 = "scalpellus")
];
const results = [
  `${miAi} wins! ${miAi}  chose ${choice2} and ${player} chose ${choice1}.`,
  `${miAi}  wins! ${miAi} chose ${choice3} and ${player} chose ${choice2}.`,
  `${miAi}  wins! ${miAi}  chose ${choice1} and ${player} chose ${choice3}.`,
  `${player} wins! The player chose ${choice2} and ${miAi}  chose ${choice1}.`,
  `${player} wins! The player chose ${choice3} and ${miAi}  chose ${choice2}.`,
  `${player} wins! The player chose ${choice1} and ${miAi}  chose ${choice3}.`
];

let playerMove = function () {
  let index1 = Math.floor(Math.random() * 3);
  let selection1 = movesList.at(index1);
  return selection1;
};

let miAiMove = function () {
  let index2 = Math.floor(Math.random() * 3);
  let selection2 = movesList.at(index2);
  return selection2;
};

const decisionMaker = function () {
  playerMove();
  miAiMove();
};

const move = () => {
  decisionMaker();
  if (playerMove() === choice1 && miAiMove() === choice2) {
    result = results[0];
  }

  if (playerMove() === choice2 && miAiMove() === choice3) {
    result = results[1];
  }

  if (playerMove() === choice3 && miAiMove() === choice1) {
    result = results[2];
  }
  ///////////////////////////////////////////

  if (miAiMove() === choice1 && playerMove() === choice2) {
    result = results[3];
  }

  if (miAiMove() === choice2 && playerMove() === choice3) {
    result = results[4];
  }

  if (miAiMove() === choice3 && playerMove() === choice1) {
    result = results[5];
  }
  if (miAiMove() === playerMove()) {
    result = "Its a Tie";
  }
  return result;
};

console.log(move());
console.log(move());