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)
相关推荐
老猿讲编程25 分钟前
一个例子来说明Ada语言的实时性支持
开发语言·ada
王哈哈^_^1 小时前
【数据集】【YOLO】【目标检测】交通事故识别数据集 8939 张,YOLO道路事故目标检测实战训练教程!
前端·人工智能·深度学习·yolo·目标检测·计算机视觉·pyqt
Chrikk1 小时前
Go-性能调优实战案例
开发语言·后端·golang
幼儿园老大*1 小时前
Go的环境搭建以及GoLand安装教程
开发语言·经验分享·后端·golang·go
canyuemanyue1 小时前
go语言连续监控事件并回调处理
开发语言·后端·golang
杜杜的man1 小时前
【go从零单排】go语言中的指针
开发语言·后端·golang
cs_dn_Jie1 小时前
钉钉 H5 微应用 手机端调试
前端·javascript·vue.js·vue·钉钉
开心工作室_kaic2 小时前
ssm068海鲜自助餐厅系统+vue(论文+源码)_kaic
前端·javascript·vue.js
有梦想的刺儿2 小时前
webWorker基本用法
前端·javascript·vue.js
cy玩具3 小时前
点击评论详情,跳到评论页面,携带对象参数写法:
前端