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

176
Visualizações
Solving Challenge -- Accessing Object Properties in a Function

Challenge:

  1. create an object named team with two properties, partner1 and partner2
  2. write a function sayTeamNames that accepts a single parameter teamObj
  3. have that sayTeamNames log both partner names separated by ' and '
  4. call sayTeamNames with your team object

const team = {
  partner1: 'Bob,
  partner2: 'Julie'
}

function sayTeamNames(teamObj) {
  for (var key in teamObj) {
    console.log(teamObj[key] + ' and ' + teamObj[key])
  }
}

sayTeamNames(team)

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

0

Two problems I see:

  1. lose the , after the Julie

  2. lose the ' for Bob

const team = {
  partner1: 'Bob',
  partner2: 'Julie',
}

function sayTeamNames(teamObj) {
  for (var key in teamObj) {
    console.log(teamObj[key] + ' and ' + teamObj[key])
  }
}

sayTeamNames(team)

Note that based on the code, it will ouput Bob and Bob Julie and Julie if you want display something like Bob and Julie, use

const team = {
  partner1: 'Bob',
  partner2: 'Julie',
}

function sayTeamNames(teamObj) {
  for (let i = 0; i < Object.keys(teamObj).length; i += 2) {
    console.log(Object.values(teamObj)[i] + ' and ' + Object.values(teamObj)[i + 1])
  }
}

sayTeamNames(team)

about 4 years ago · Juan Pablo Isaza Relatório

0

you could do something like this

  const team = {
          partner1: 'Bob',
          partner2: 'Julie'
        }
    
        function sayTeamNames(teamObj) {
          console.log(Object.values(teamObj).join(' and '))
        }
    
        sayTeamNames(team)
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