0

Create a function multiplyNumeric(objectExample) that multiplies all numeric properties of objectExample by 2. Where may be my mistake?

let objectExample = {
    width: 200,
    height: 300,
    title: 'example'
}

let multiplyNumeric = (key, object) => {
    for (let key in object) {
        if (typeof object.key === 'number') {
            object.key *= 2;
        }
    }
}

multiplyNumeric(objectExample);

console.log(objectExample);


Thank You very much.

1 Answers1

2

let objectExample = {
  width: 200,
  height: 300,
  title: 'example'
}

let multiplyNumeric = obj => {
  for (let [key, value] of Object.entries(obj)) {
    if (typeof value === 'number') {
      obj[key] = value * 2;
    }
  }
}

multiplyNumeric(objectExample);
console.log(objectExample);
Daan
  • 2,680
  • 20
  • 39