在JavaScript中将humanYears转换为catYears和dogYears
问题
我们需要编写一个JavaScript函数,该函数将人类的年龄以年为单位,并返回各自的dogYears和catYears。
输入
const humanYears = 15;
输出
const output = [ 15, 76, 89 ];
示例
以下是代码-
const humanYears = 15;
const humanYearsCatYearsDogYears = (humanYears) => {
let catYears = 0;
let dogYears = 0;
for (let i = 1; i <= humanYears; i++) {
if (i === 1) {
catYears += 15;
dogYears += 15;
}else if (i === 2) {
catYears += 9;
dogYears += 9;
}else {
catYears += 4;
dogYears += 5;
}
}
return [humanYears, catYears, dogYears];
};
console.log(humanYearsCatYearsDogYears(humanYears));输出结果
[ 15, 76, 89 ]
热门推荐
10 奶奶生日感恩祝福语简短
11 满月100天简短祝福语
12 写给老师祝福语简短大学
13 杨奕老师祝福语简短
14 结婚祝福语简短精辟 兄弟
15 家长祝福语大全简短内容
16 足球队祝福语简短
17 女儿生日祝福语说说简短
18 好兄弟订婚祝福语简短