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());
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 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
…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
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
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