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)
相关推荐
我能坚持多久3 分钟前
D22—C语言预处理详解:从宏定义到条件编译
c语言·开发语言
小猪咪piggy6 分钟前
【Python】(3) 函数
开发语言·python
青岑CTF15 分钟前
攻防世界-Php_rce-胎教版wp
开发语言·安全·web安全·网络安全·php
初次见面我叫泰隆31 分钟前
Qt——4、Qt窗口
开发语言·qt·客户端开发
瑞雪兆丰年兮36 分钟前
[从0开始学Java|第十一天]学生管理系统
java·开发语言
phltxy1 小时前
Vue3入门指南:从环境搭建到数据响应式,开启高效前端开发之旅
前端·javascript·vue.js
小飞大王6661 小时前
CSS基础知识
前端·css
代码AI弗森1 小时前
Git Bash 与 PowerShell:定位差异、使用场景与选择建议
开发语言·git·bash
Charlie_lll1 小时前
学习Three.js–风车星系
前端·three.js
代码游侠1 小时前
学习笔记——Linux内核与嵌入式开发1
linux·运维·前端·arm开发·单片机·嵌入式硬件·学习