const number1 = 103;
const number2 = 72;
const number3 = 189;
// getMax関数を定義してください
const getMax = (a, b, c) => {
let max = a > b ? a : b;
max = max > c ? max : c;
return max;
};
// 「最大値は○○です」と出力してください
console.log(`最大値は${getMax(number1, number2, number3)}です`);
const getMax1 = (a, b, c) => {
let max = a;
if (max < b) {
max = b;
}
if (max < c) {
max = c;
}
return max;
};
const max = getMax1(number1, number2, number3);
console.log(`最大値は${max}です`);
/*
最大値は189です
最大値は189です
*/
JavaScript两种方法求3个数里的最大值
最新推荐文章于 2024-01-13 12:31:31 发布