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

175
Views
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 answers
Answer question

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 Report

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 Report
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!