Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Referencing a function argument from a seperate object?

I'm currently working on a Rock-paper-scissors project, but ran into a bit of a problem regarding lexical scopping (at least, I believe that's the issue). The game works by having the user click on one of four options (RPS, and 'clear', which clears the developer console). Once the user clicks any of the first three items, which are part of an array, a sibling number is randomly generated to immediately compare in the getResults() function.

HTML:

<button class = "btn" id = "rock">rock</button>
<button class = "btn" id = "paper">paper</button>
<button class = "btn" id = "scissors">scissors</button>
<button class = "btn" id = "clear">clear</button>

Javascript:

const say = (word) => {console.log(word)};
const rps = {
choiceStack: ["rock", "paper", "scissors"],
rMap: [
 ["t", "u", "c"],
 ["c", "t", "u"],
 ["u", "c", "t"]
],
//Trying to figure out how to carry-on the user's value from getResults()
res: {
get "t" () {say("draw")},
get "u" () {say(`user chose: ${user} you win`)},
get "c" () {say(`computer chose: ${comp} you lose`)},
}
};

const button = document.getElementsByClassName("btn"),
   arrBtn = Array.from(button);

let userInput = arrBtn.forEach(list => {
list.addEventListener('click', e => {
 list.id === "clear" ? console.clear()
: getResults(arrBtn.indexOf(list), Math.floor(Math.random() * 3))
})
});

//Is there a way to enter the user's input into rps.res methods?
function getResults(user, comp) {
say(rps.res[rps.rMap[user][comp]]);

The issue I'm currently facing is pulling both parameters that were within getResults() into the rps object (specifically the string within rps.res, if that makes sense). If that is possible, is there a proper term that's used for situations like this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!