我想同时显示英里每小时和公里每小时。那可能吗?
如何实现公里每小时计算并一起显示?
function getMiles (knots) {
var mph = (knots * 1.15078);
var speed = Math.round(mph);
if (speed < 50) {
return speed + console.log('mhp ');
}
if (speed > 50) {
return speed + console.log('mph , wind can be too strong today ');
};
}getMiles()
最佳答案
您返回较早,添加 kph 并将其连接起来。
const wind = knots => {
const miles = Math.round(knots * 1.15078)
const kph = Math.round(knots * 1.852)
return `${miles} mph / ${kph} kph ` + (
miles > 50 ? 'wind can be too strong today' : ''
)
}
console.log(wind(80))
关于javascript - 一起显示英里每小时和公里每小时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61237752/