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

106
Views
Javascript indexOf () no funciona con matriz

Estoy tratando de usar indexOf() para obtener el índice de una cadena dentro de una matriz, en una de las funciones funciona bien, pero no funciona en otra función. Una función es agregar un jugador, la otra es actualizar la puntuación de un jugador. Ambas usan el nombre del jugador como parámetro Aquí está mi código:

 let ScoreBoard = { testEntry: ["Chuck Norris", 1000000000], scoreList: [] } let menu = 0 let playerName = "" let playerScore = 0 while (menu != "4") { menu = prompt("Type 1 to add a player, 2 to remove a player, 3 to update player's score or 4 to exit") switch (menu) { case "1": playerName = prompt("What is the name of the player") playerScore = parseInt(prompt("What is the player score")) AddPlayer(playerName, playerScore) console.log(ScoreBoard) break; case "2": playerName = prompt("What is the name of the player"); playerScore = parseInt(prompt("What is the player score")) RemovePlayer(playerScore, playerName) console.log(ScoreBoard) break; case "3": playerName = prompt("What is the name of the player"); playerScore = parseInt(prompt("What is the player score")) let newScore = parseInt(prompt("What is the new score?")) UpdateScore(playerScore, playerName, newScore) console.log(ScoreBoard) break; } } function AddPlayer(name, score, highscore) { highscore = ScoreBoard.testEntry let newEntry = [name, score] ScoreBoard.scoreList.push(newEntry) return ScoreBoard } function RemovePlayer(score, name) { let index = ScoreBoard.scoreList.indexOf(name) ScoreBoard.scoreList.splice(index) return ScoreBoard } function UpdateScore(score, name, newScore) { let updatedScore = score + newScore console.log(updatedScore) let index = ScoreBoard.scoreList.indexOf(name) console.log(index) //let scoreIndex = ScoreBoard.scoreList.indexOf(score) //console.log(scoreIndex) ScoreBoard.scoreList.map(function (element){updatedScore = element[index] return ScoreBoard }) }

La lógica de obtener el índice tanto en la función RemovePlayer() como en UpdateScore() es la misma, así que no sé qué estoy haciendo mal. Lo siento si no estoy siendo muy claro, el inglés no es mi primer idioma.

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!