0036【Edabit ★☆☆☆☆☆】【让我加油】Let‘s Fuel Up!

0036【Edabit ★☆☆☆☆☆】【让我加油 】Let's Fuel Up!

control_flow language_fundamentals numbers

Instructions

A vehicle needs 10 times the amount of fuel than the distance it travels. However, it must always carry a minimum of 100 fuel before setting off.

Create a function which calculates the amount of fuel it needs, given the distance.

Examples
javascript 复制代码
calculateFuel(15) // 150
calculateFuel(23.5) // 235
calculateFuel(3) // 100
Notes
  • Distance will be a number greater than zero.
  • Return 100 if the calculated fuel turns out to be less than 100.
Solutions
javascript 复制代码
function calculateFuel(n) {
	let ans = n * 10;
	return ans < 100? 100:ans;
}
TestCases
javascript 复制代码
let Test = (function(){
    return {
        assertEquals:function(actual,expected){
            if(actual !== expected){
                let errorMsg = `actual is ${actual},${expected} is expected`;
                throw new Error(errorMsg);
            }
        }
    }
})();

Test.assertEquals(calculateFuel(15), 150)
Test.assertEquals(calculateFuel(23), 230)
Test.assertEquals(calculateFuel(10), 100)
Test.assertEquals(calculateFuel(3), 100)
Test.assertEquals(calculateFuel(23.5), 235)
Test.assertEquals(calculateFuel(3.14), 100)
Test.assertEquals(calculateFuel(9.99999), 100)
Test.assertEquals(calculateFuel(822315322), 8223153220)
Test.assertEquals(calculateFuel(12345.6789), 123456.789)
Test.assertEquals(calculateFuel(31.41), 314.1)
相关推荐
码匠许师傅7 小时前
【C++三方组件】POCO:跨平台系统编程全家桶
开发语言·c++
米米商聊8 小时前
同名附件为什么被 Map 覆盖?重复键与一对多索引
前端·javascript
bkspiderx8 小时前
基于Socket的广播通信及C语言实现详解
c语言·开发语言·socket·广播·socket的广播通信
小王C语言8 小时前
Qt常用控件:输入类控件,单行/多行输入框、下拉框、(日期)微调框、旋钮、滑动条
开发语言·qt
ESDWAN8 小时前
SD-WAN 主备切换为什么仍然会断网?从检测机制到会话恢复分析
开发语言·php
1001101_QIA8 小时前
.exe does not seem to be a Qt executable.
开发语言·qt
echome8889 小时前
Python 异常处理:try、else、finally 的正确搭配
开发语言·前端·python·异常处理·编程技巧
云和数据.ChenGuang9 小时前
Python 单继承与多继承深度剖析:从 MRO 到实战取舍
开发语言·人工智能·python·langchain
时间的情敌9 小时前
OpenLayers 实战|Vue3 + OpenLayers 完整工程案例(加载天地图、要素、弹窗、绘制、WFS)
前端·openlayers
陈随易9 小时前
下载神器!Motrix 停更三年后重写回归
前端·后端·程序员