每日js练习

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了每日js练习相关的知识,希望对你有一定的参考价值。

第一次玩codewars,选了个最简单的题目

要求是:

You have to write a function that describe Leo:

if oscar was (integer) 88, you have to return "Leo finally won the oscar! Leo is happy".
if oscar was 86, you have to return "Not even for Wolf of wallstreet?!"
if it was not 88 or 86 (and below 88) you should return "When will you give Leo an Oscar?"
if it was over 88 you should return "Leo got one already!"

简单吧

function leo(oscar){
    if(oscar>88){
        return "Leo got one already!";
    }else if(oscar==88){
        return "Leo finally won the oscar! Leo is happy";
    }else if(oscar==86){
        return "Not even for Wolf of wallstreet?!"
    }else{
        return "When will you give Leo an Oscar?"
    }
}                    

我想当然的就这样写了;

然后看了一下最佳答案

const leo = (oscar) => {
  return oscar === 88 ? ‘Leo finally won the oscar! Leo is happy‘ :
         oscar === 86 ? ‘Not even for Wolf of wallstreet?!‘       :
         oscar  <  88 ? ‘When will you give Leo an Oscar?‘        :
         ‘Leo got one already!‘;
};

ES6语法加3元运算符,哇塞

以上是关于每日js练习的主要内容,如果未能解决你的问题,请参考以下文章

超出未经身份验证的使用的每日限制。继续使用需要注册错误

每日一题||二叉树练习

寒假每日一题回文平方(个人练习)详细题解+推导证明(第五天)

每日算法练习(2020-1-10)

markdown 每日片段

HTTP专项练习,每日一解析2022/05/09