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)
相关推荐
码云之上1 分钟前
Context Engineering:让 Agent 在当前步骤看到正确的事实
前端·人工智能·前端工程化
夜雪一千6 分钟前
Python从HTML提取纯文本、去空格、比对内容是否变化:方案+合理性分析
开发语言·python·html
烂蜻蜓12 分钟前
Node.js入门教程(一):初识Node.js——服务端JavaScript的诞生与特点
开发语言·javascript·node.js
嘟嘟071721 分钟前
从手写 HashRouter 到 React Router:逐层拆解 SPA 前端路由的完整实现
前端·javascript
我叫蒙奇1 小时前
JS中的隐式类型转换
前端
他们叫我秃子1 小时前
前端开发转 Go 全栈(四):代码写在前面,却要最后执行?我终于搞懂了 defer
前端·后端·go
生戎马 平安京策1 小时前
只学一点点:我的技术学习策略
前端·javascript·react.js
大鹏说大话1 小时前
HTML5 地理定位 Geolocation:获取用户位置的“红线”与最佳实践
前端·html·html5
Csvn2 小时前
content-visibility: auto —— 让浏览器跳过离屏渲染的性能黑科技
前端
小鹰信息技术服务部2 小时前
Edge安装包MicrosoftEdgeSetup.exe无法运行,点击没反应
前端·edge