Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
Try to solve problem solving using JavaScript

I am facing a problem with this issue

this is the question

enter image description here

This is my solution

let whigt = {
  A: 1,
  B: 2,
  C: 3,
  D: 1,
  E: 2,
  F: 3,
  G: 1,
  H: 2,
  I: 3,
  J: 1,
  K: 2,
  L: 3,
  M: 1,
  N: 2,
  O: 3,
  P: 1,
  Q: 2,
  R: 3,
  S: 4,
  T: 1,
  U: 2,
  V: 3,
  W: 1,
  X: 2,
  Y: 3,
  Z: 4
}

let charwhigt = 0;

function presses(phrase) {
  let arraychar = phrase.toUpperCase().split("");
  arraychar.map((el) => {
    console.log(whigt.el)

  })
}

presses("omar")

I'm trying to link the object key to the letter, but when I print the object's value, it gives me the output NAN

What is my mistake did and what is the solution to make the solution right؟؟

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your code try to search el into whigt instead use [el] will search value of el

let whigt = {
  A: 1,
  B: 2,
  C: 3,
  D: 1,
  E: 2,
  F: 3,
  G: 1,
  H: 2,
  I: 3,
  J: 1,
  K: 2,
  L: 3,
  M: 1,
  N: 2,
  O: 3,
  P: 1,
  Q: 2,
  R: 3,
  S: 4,
  T: 1,
  U: 2,
  V: 3,
  W: 1,
  X: 2,
  Y: 3,
  Z: 4
}

let charwhigt = 0;

function presses(phrase) {
  let arraychar = phrase.toUpperCase().split("");
  arraychar.forEach((el) => {    
    console.log(whigt[el]);
  });
}

presses("omar");

PS: i prefer use forEach for loop array, see the differente here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda