0059【Edabit ★☆☆☆☆☆】【是否被允许喝酒】Drinks Allowed?

编程入门 行业动态 更新时间:2024-10-27 14:24:17

0059【<a href=https://www.elefans.com/category/jswz/34/1666502.html style=Edabit ★☆☆☆☆☆】【是否被允许喝酒】Drinks Allowed?"/>

0059【Edabit ★☆☆☆☆☆】【是否被允许喝酒】Drinks Allowed?

0059【Edabit ★☆☆☆☆☆】【是否被允许喝酒】Drinks Allowed?

conditions language_fundamentals logic validation

Instructions

A bartender is writing a simple program to determine whether he should serve drinks to someone. He only serves drinks to people 18 and older and when he’s not on break.

Given the person’s age, and whether break time is in session, create a function which returns whether he should serve drinks.

Examples
shouldServeDrinks(17, true) // false
shouldServeDrinks(19, false) // true
shouldServeDrinks(30, true) // false
Notes
  • Return true or false.
  • Some countries have a slightly higher drinking age, but for the purposes of this challenge, it will be 18.
Solutions
function shouldServeDrinks(age, onBreak) {return age>=18 && !onBreak
}
TestCases
let Test = (function(){return {assertEquals:function(actual,expected){if(actual !== expected){let errorMsg = `actual is ${actual},${expected} is expected`;throw new Error(errorMsg);}},assertSimilar:function(actual,expected){if(actual.length != expected.length){throw new Error(`length is not equals, ${actual},${expected}`);}for(let a of actual){if(!expected.includes(a)){throw new Error(`missing ${a}`);}}}}
})();Test.assertEquals(shouldServeDrinks(17, true), false)
Test.assertEquals(shouldServeDrinks(30, true), false)
Test.assertEquals(shouldServeDrinks(24, false), true)
Test.assertEquals(shouldServeDrinks(18, false), true)
Test.assertEquals(shouldServeDrinks(3, false), false)

更多推荐

0059【Edabit ★☆☆☆☆☆】【是否被允许喝酒】Drinks Allowed?

本文发布于:2023-11-16 18:53:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631588.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Edabit   Allowed   Drinks

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!