谁能帮助我并向我解释如何在if / else语句中使用运算符,我正在尝试做一些简单的事情并得到两个不同乘法的结果,我是一个自学成才的开发人员,请耐心等待



var oscar = {
  height: 155,
  age: 22,
};
var andrew = {
  height: 170,
  age: 16,
};

if ((oscar * 5) > (andrew * 5)) {
  console.log('Oscar is the winner');
} else if ((oscar * 5) < (andrew * 5)) {
  console.log('Andrew is the winner')
} else {
  console.log('No winner')
}

最佳答案

变量是对象,必须指定比较的属性。
无需乘以5。



var oscar = {
  height: 155,
  age: 22
};
var andrew = {
  height: 170,
  age: 16
};

if ((oscar.height) > (andrew.height)) {
  console.log('Oscar is the winner');
} else if ((oscar.height) < (andrew.height)) {
  console.log('Andrew is the winner')
} else {
  console.log('No winner')
}

07-26 00:16